Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86362 - trunk/boost/sync/detail/semaphore
From: andrey.semashev_at_[hidden]
Date: 2013-10-19 09:53:57


Author: andysem
Date: 2013-10-19 09:53:56 EDT (Sat, 19 Oct 2013)
New Revision: 86362
URL: http://svn.boost.org/trac/boost/changeset/86362

Log:
Fixed semaphore test.

Text files modified:
   trunk/boost/sync/detail/semaphore/semaphore_dispatch.hpp | 12 +++++++++---
   1 files changed, 9 insertions(+), 3 deletions(-)

Modified: trunk/boost/sync/detail/semaphore/semaphore_dispatch.hpp
==============================================================================
--- trunk/boost/sync/detail/semaphore/semaphore_dispatch.hpp Sat Oct 19 06:23:37 2013 (r86361)
+++ trunk/boost/sync/detail/semaphore/semaphore_dispatch.hpp 2013-10-19 09:53:56 EDT (Sat, 19 Oct 2013) (r86362)
@@ -42,9 +42,15 @@
 public:
     explicit semaphore(unsigned int i = 0)
     {
- m_sem = dispatch_semaphore_create(i);
+ // Note that dispatch_release requires the semaphore counter to be equal to the one specified for dispatch_semaphore_create.
+ // Otherwise dispatch_release just crashes. This is probably a bug in libdispatch, but in order to work around it, we have to
+ // set the counter manually in a loop, after creating the semaphore.
+ m_sem = dispatch_semaphore_create(0);
         if (m_sem == NULL)
- BOOST_SYNC_DETAIL_THROW(resource_error, (sync::detail::system_ns::errc::not_enough_memory)("boost::sync::semaphore constructor failed in dispatch_semaphore_create"));
+ BOOST_SYNC_DETAIL_THROW(resource_error, (sync::detail::system_ns::errc::not_enough_memory)("semaphore constructor failed in dispatch_semaphore_create"));
+
+ for (; i > 0; --i)
+ dispatch_semaphore_signal(m_sem);
     }
 
     ~semaphore()
@@ -112,7 +118,7 @@
 
     bool priv_timed_wait(sync::detail::system_time_point const& t)
     {
- return dispatch_semaphore_wait(m_sem, dispatch_walltime(const_cast< struct ::timespec* >(&t.get()), 0)) == 0;
+ return priv_timed_wait(t - sync::detail::system_time_point::now());
     }
 
     template< typename TimePoint >


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk