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 Alexander Terekhov other posts by this author
Jul 19 2004 5:15PM messages near this date
Re: [boost] Re: [Boost.Thread] mutex Win32 implementation changes | Re: [boost] Re: [Boost.Thread] mutex Win32 implementation changes
Peter Dimov wrote:
>  
>  Alexander Terekhov wrote:
>  >
>  > With respect to swap_based_mutex_for_windows thing (without
>  > pimpl-and-never-destroyed-impl), the problem is that it can go boom
>  > in unlock().
>  >
>  >   void lock() throw() {
>  >     if (m_lock_status.swap(1, msync::acq))
>  >       while (m_lock_status.swap(-1, msync::acq))
>  >         m_retry_event.wait();
>  >   }
>  >
>  >   void unlock() throw() {
>  >     if (m_lock_status.swap(0, msync::rel) < 0)
>  >       m_retry_event.set();
>  >   }
>  >
>  > Scenario...
>  >
>  >   Given: mutex protected refcounting. Two threads, A and B.
>  >
>  >      t0: thread A locks the mutex and decrements refcount to 2;
>  >
>  >      t1: thread B does m_lock_status.swap(1, msync::acq) on the
>  >          fast path and sees 1;
>  >
>  >      t2: thread A unlocks the mutex (doesn't enter slow path);
>  >
>  >      t3: thread B does mutex m_lock_status.swap(-1, msync::acq),
>  >          locks the mutex, decrements refcount to 1, does
>  >          m_lock_status.swap(0, msync::rel) and enters slow path
>  >          in unlock();
>  
>      SetEvent( e_ );

Nah, it suspends right before it.

>  
>  >      t4: thread A locks the mutex, decrements refcount to 0,
>  >          unlocks the mutex, and destroys it (including event);
>  
>      CloseHandle( e_ );

and operator delete() [with subsequent "unmap"].

>  
>  >      t5: thread B goes BOOM.
>  
>  Does it? The Win32 kernel is pretty resilient. ;-) We'll have to try it, I
>  guess.

First problem is access to freed memory. But even of you save 
event handle on the stack, you risk to break something because
the same handle might now point to a new event object... in 
something that can't handle spurious wakes on it.

regards,
alexander.

_______________________________________________
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