ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
[boost] Re: [Boost.Thread] mutex Win32 implementation changes
by Michael Glassford other posts by this author
Jul 15 2004 8:49PM messages near this date
[boost] Re: [Boost.Thread] mutex Win32 implementation changes | [boost] Re: Latest ScopeGuard
Alexander Terekhov wrote:

>  Michael Glassford wrote:
>  [...]
>  
> >Do you have a full-fledged implementation for such a beast? 
>  
>  
>  Trade secret.
>  
>  
> >I remember you posting sample code some time back, ...
>  
>  
>  class swap_based_mutex_for_windows { // noncopyable
>  
>    atomic<int>      m_lock_status; // 0: free, 1/-1: locked/contention
>    auto_reset_event m_retry_event; 
>  
>  public:
>  
>    // 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))
>          m_retry_event.wait();
>    } 
>  
>    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) 
>        m_retry_event.set();
>    } 
>  
>  };

Looking at this again, it's not entirely clear to me what the return 
value of atomic<int> ::swap() is. Can you clarify?

Thanks,

Mike

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Michael Glassford
Alexander Terekhov
Alexander Terekhov
Alexander Terekhov
Peter Dimov
Alexander Terekhov
Alexander Terekhov
Alexander Terekhov
val salamakha
val salamakha
val salamakha
val salamakha
Peter Dimov
Alexander Terekhov
Peter Dimov
Alexander Terekhov
Peter Dimov
Peter Dimov
Alexander Terekhov
Peter Dimov
Alexander Terekhov
Alexander Terekhov
Alexander Terekhov
Alexander Terekhov
Alexander Terekhov
Michael Glassford
Alexander Terekhov
Michael Glassford

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved