Re: [boost] Question about boost::thread::yield for Win32

2003-02-25 Thread William E. Kempf

Russell Hind said:
> Is yield intended to always yield to another thread if one can run?
> Because  the code for yield is
>
> void thread::yield()
> {
> #if defined(BOOST_HAS_WINTHREADS)
>  Sleep(0);
> #elif defined(BOOST_HAS_PTHREADS)
> #   if defined(BOOST_HAS_SCHED_YIELD)
>  int res = 0;
>  res = sched_yield();
>  assert(res == 0);
> #   elif defined(BOOST_HAS_PTHREAD_YIELD)
>  int res = 0;
>  res = pthread_yield();
>  assert(res == 0);
> #   else
>  xtime xt;
>  xtime_get(&xt, TIME_UTC);
>  sleep(xt);
> #   endif
> #elif defined(BOOST_HAS_MPTASKS)
>  MPYield();
> #endif
> }
>
> 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.
>
>  Sleep(1);
>  }
>  }
>
> (I don't actually use yield yet, so currently have no preference for
> either, but just wondered what the intended use of yield was)

I'll look into this and fix it.  Thanks.

-- 
William E. Kempf


___
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Re: [boost] Question about boost::thread::yield for Win32

2003-03-01 Thread Victor A. Wagner, Jr.
What is there to fix?  Of course yield only yields to equal priority 
threads (one hopes that higher priority threads have already pre-empted).

At Tuesday 2003/02/25 08:26, you wrote:

Russell Hind said:
> Is yield intended to always yield to another thread if one can run?
> Because  the code for yield is
>
> void thread::yield()
> {
> #if defined(BOOST_HAS_WINTHREADS)
>  Sleep(0);
> #elif defined(BOOST_HAS_PTHREADS)
> #   if defined(BOOST_HAS_SCHED_YIELD)
>  int res = 0;
>  res = sched_yield();
>  assert(res == 0);
> #   elif defined(BOOST_HAS_PTHREAD_YIELD)
>  int res = 0;
>  res = pthread_yield();
>  assert(res == 0);
> #   else
>  xtime xt;
>  xtime_get(&xt, TIME_UTC);
>  sleep(xt);
> #   endif
> #elif defined(BOOST_HAS_MPTASKS)
>  MPYield();
> #endif
> }
>
> 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.
>
>  Sleep(1);
>  }
>  }
>
> (I don't actually use yield yet, so currently have no preference for
> either, but just wondered what the intended use of yield was)
I'll look into this and fix it.  Thanks.

--
William E. Kempf
___
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Victor A. Wagner Jr.  http://rudbek.com
The five most dangerous words in the English language:
  "There oughta be a law"
___
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost