Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2004-06-12 10:24:55

Chuck Allison wrote:
> viewing at The idea is to have

Quoting from Few comments

<quote author=Bjarne Stroustrup>

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


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


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


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

class swap_based_mutex_for_windows { // noncopyable

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


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

  void lock() throw() {
    if (m_lock_status.swap(1, msync::acq))
      while (m_lock_status.swap(-1, msync::acq))

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

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

  void unlock() throw() {
    if (m_lock_status.swap(0, msync::rel) < 0)



Boost list run by bdawes at, gregod at, cpdaniel at, john at