This is the mail archive of the
pthreads-win32@sourceware.org
mailing list for the pthreas-win32 project.
patch for sched_yield()
- From: Virgilio Alexandre Fornazin <virgilio_fornazin at yahoo dot com dot br>
- To: pthreads-win32 at sourceware dot org
- Date: Wed, 22 Aug 2007 17:39:04 -0300 (ART)
- Subject: patch for sched_yield()
Hi
I did a change in sched_yield() to support
multi-processor systems after checking the OS (NT
style oses). I managed to compile it under VS2005 SP1.
I'm putting the code here to share with pthreads
project.
I changed the implementation from:
{
Sleep (0);
return 0;
}
To:
{
static OSVERSIONINFO vs = {0};
if (vs.dwOSVersionInfoSize == 0)
{
vs.dwOSVersionInfoSize = sizeof(vs);
GetVersionEx(&vs);
}
if (vs.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
SwitchToThread ();
}
else
{
Sleep (0);
}
return 0;
}
I saw in another mailing list that Sleep(0) sometimes
doesn't yield the thread and performs nothing on some
Windows versions.
I hope this help somebody and could be integrated to
main code after more testing with other cpu/configurations.
Flickr agora em português. Você clica, todo mundo vê.
http://www.flickr.com.br/