+ Reply to Thread
Results 1 to 2 of 2

Thread: What should I use SwitchToThread or Sleep(0)?

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    43

    What should I use SwitchToThread or Sleep(0)?

    I saw that there are two APIs SwitchToThread and Sleep(0) to yield the processor.

    Which one should I use and what is recommended?

    Help me with this.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    23
    If you are using multiprocessor machine then you should consider using Sleep/SleepEx over SwitchToThread:

    a. SwitchToThread works on the processor it is called from. If a thread waiting on another CPU it won't switch to another processor.
    b. SwitchToThread does not awake more than one thread at a time even if there are more threads waiting for CPU. As in case of SleepEx, which can awake more then one thread based on the condition it meets.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts