Boost logo

Boost :

From: Chuck Allison (chuck_at_[hidden])
Date: 2004-06-12 15:02:47


Hello Alexander,

I'm sorry, but that page is just a sample page. Bjarne's article is
not an official posting. We haven't launched yet. If you want to
discuss the content of Bjarne's comments, you can email him directly,
but it has nothing to do with The C++ Source. Sorry if I didn't make
it clear that that page was just a sample. I meant to.

Saturday, June 12, 2004, 11:01:35 AM, you wrote:
brlbo> Chuck Allison wrote:
brlbo> [...]
>> viewing at http://www.artima.com/cppsource. The idea is to have

brlbo> Quoting from http://www.artima.com/intv/elegance.html. Few comments
brlbo> follow.

brlbo> <quote author=Bjarne Stroustrup>

brlbo> I don't put in specific features for concurrency, because you can put
brlbo> them in a library.

brlbo> </quote>

brlbo> You can't do that without threaded memory model, to begin with.

brlbo> <quote>

brlbo> C was designed with the principle that you should be able to write
brlbo> its standard library in the language itself. That same principle
brlbo> guided the design of C++.

brlbo> </quote>

brlbo> Show me the the standard C++ impl of atomic<> for a rather simple
brlbo> thing like

brlbo> class swap_based_mutex_for_windows { // noncopyable

brlbo> atomic<int> m_lock_status; // 0: free, 1/-1: locked/contention
brlbo> auto_reset_event m_retry_event; // "slow" bin sema/gate

brlbo> public:

brlbo> // ctor/dtor [w/o lazy event init]

brlbo> void lock() throw() {
brlbo> if (m_lock_status.swap(1, msync::acq))
brlbo> while (m_lock_status.swap(-1, msync::acq))
brlbo> m_retry_event.wait();
brlbo> }

brlbo> bool trylock() throw() {
brlbo> return !m_lock_status.swap(1, msync::acq) ?
brlbo> true : !m_lock_status.swap(-1, msync::acq);
brlbo> }

brlbo> bool timedlock(absolute_timeout const & timeout) throw() {
brlbo> if (m_lock_status.swap(1, msync::acq)) {
brlbo> while (m_lock_status.swap(-1, msync::acq))
brlbo> if (!m_retry_event.timedwait(timeout))
brlbo> return false;
brlbo> }
brlbo> return true;
brlbo> }

brlbo> void unlock() throw() {
brlbo> if (m_lock_status.swap(0, msync::rel) < 0)
brlbo> m_retry_event.set();
brlbo> }

brlbo> };

brlbo> regards,
brlbo> alexander.

-- 
Best regards,
 Chuck

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk