Boost logo

Boost :

From: Russell Hind (rhind_at_[hidden])
Date: 2003-02-25 08:06:52

Is yield intended to always yield to another thread if one can run?
Because the code for yield is

void thread::yield()
#elif defined(BOOST_HAS_PTHREADS)
     int res = 0;
     res = sched_yield();
     assert(res == 0);
     int res = 0;
     res = pthread_yield();
     assert(res == 0);
# else
     xtime xt;
     xtime_get(&xt, TIME_UTC);
# endif
#elif defined(BOOST_HAS_MPTASKS)

Taken from the main CVS.

Sleep(0) on Win32 will only yield to another thread of equal or higher
priority, not to lower priority threads.

In boost::detail::lightweight_mutex::scoped_lock, it is mentioned that
Sleep(1) will get around. Is the behaviour of Sleep(0) the intended use
of yield?

         explicit scoped_lock(lightweight_mutex & m): m_(m)
             while( InterlockedExchange(&m_.l_, 1) )
                 // Note: changed to Sleep(1) from Sleep(0).
                 // According to MSDN, Sleep(0) will never yield
                 // to a lower-priority thread, whereas Sleep(1)
                 // will. Performance seems not to be affected.


(I don't actually use yield yet, so currently have no preference for
either, but just wondered what the intended use of yield was)



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