# Is the way an OS schedule threads related to parallel computing?

From Wikipedia:

Operating systems schedule threads in one of two ways:

Preemptive multitasking is generally considered the superior approach, as it allows the operating system to determine when a context switch should occur. The disadvantage of preemptive multithreading is that the system may make a context switch at an inappropriate time, causing lock convoy, priority inversion or other negative effects, which may be avoided by cooperative multithreading.

Cooperative multithreading, on the other hand, relies on the threads themselves to relinquish control once they are at a stopping point. This can create problems if a thread is waiting for a resource to become available.

I wonder if in parallel computing (writing and running parallelized programs in OpenMP, OpenMPI, pThread), which of Cooperative multithreading and Preemptive multitasking is/are used, or does the way OS scheduling threads have nothing to do with the multi-process or multi-thread within a parallelized program?

• What reading and research have you done to answer your question on your own? Have you read a textbook chapter on scheduling in an OS textbook? – D.W. Apr 26 '14 at 22:00
• I don't have an OS textbook. I read Wikipedia. – Tim Apr 26 '14 at 22:01
• We expect you to do more research than just reading Wikipedia, before asking here. You might want to try doing some searching and reading on sources that are available to you -- or visit a library. There's not a lot of value to the world in us re-typing out an explanation of something that's already explained in many standard textbooks. – D.W. Apr 26 '14 at 22:03
• I have done the research that I can. believe it or not. Unlike cstheory.SE, Isn't CS.SE supposed to be friendly to newbies? – Tim Apr 26 '14 at 22:05
• There's a lot of additional research you could do! If you stopped after reading Wikipedia, you aren't being resourceful enough. There are many resources on threads, operating systems, and schedulers on the Internet -- and Google can help you find them. It's not a question of being friendly or unfriendly; it's a matter of following site rules, and my expectations on this site are that you will do substantial research before asking. See How much research effort is expected of Stack Overflow users?. – D.W. Apr 26 '14 at 22:09

With cooperative multithreading you break the illusion of having multiple processors. If a thread gets scheduled it runs as long as it wants to (and knows that the other thread is not running) and only gives up the processor by calling some system call (often called something like yield().) On the one hand, you've lost the illusion of two processors, which is problematic if one of the threads forgets to yield(). The advantage is that you know when the the threads are switching back and forth, so the number of possible interleavings you need to reason about is much smaller.