This is the mail archive of the pthreads-win32@sourceware.org mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]