In article <3e0374e6.0307161452.579a22fcposting.google.com >,
Loic Domaigne <loic-devgmx.net> wrote:Actually, if it's POSIX conformant, a thread absolutely MUST NOT be able>Hi!
>>>>>> > If one thread is blocking in read() call, can other thread in the same
>> > process run at the same time?
>> > I just want to know, whether blocking in read() call is actually
>> > blocking the whole process.
>> It depends on your threads implementation. What are you using? POSIX
>> pthreads does not block the whole process.
>Yes, the outcome depends on the threads implementation. However, it is
>incorrect to believe that a POSIX conformant implementation won't
>block the whole process. In fact, everything depends on "how much does
>the kernel scheduler know about threads".
to block the rest of the threads by calling a POSIX API function.
If such a library is attempting to be POSIX, it will have provided>There is 3 common models for threads implementation:
>- "M to 1" or "user space" model: The notion of threads is only known
>by the threads library. The threads are scheduled by the library
>itself. On the kernel side, the whole MT-process is viewed as "one
>process". IOW, the kernel has no notion of "threads". Unless the
>library provides some wrappers for the system calls, if one thread
>issues a blocking system call, it is likely that the whole process
wrappers for all such functions.
Actually, Solaris' current implementation is 1 to 1. It's astonishingly>- "1 to 1" model: to each thread in the process is a kernel thread
>associated with. It that latter case, when a thread blocks in a system
>call, only that particular thread goes to the "suspend state". The
>other threads get scheduled as normal, and if one is runnable, it will
>acquire the CPU. As a result the whole process isn't blocked.
>- "M to N" aka "2 level scheduler" model: This is a mix between the
>two previous models. M threads are mapped to N kernel threads, with
>eventually M > N. This means that a kernel thread might be responsible
>for 2 or more threads of the process. The same problem might occurred
>as for the "M to 1" model. However, some implementations like Solaris
>(a well known two level implementation) use some tricks, in other to
>avoid that the all the LWPs mapped to one kernel thread gets blocked.
hard to get MxN thread scheduling working correctly, and Sun finally
stopped trying. This is probably a good thing, in the long run.
The only threads package in wide use (that I'm aware of) in which a>In conclusion: You can only answer that question if you know the model
>implemented by the Pthreads lib, or experiment if you don't. If you
>tell us the OS / Pthreads implementation used, this should be
>sufficient to give you the exact answer.
single thread can block the whole process is GNU Pth. And there
are even optional wrappers there for most platforms.
It's extremely rare to find such a hopelessly broken thread
implementation (i.e. one that allows such blocking) these days.
Steve Watt KD6GGD PP-ASEL-IA ICBM: 121W 56' 57.8" / 37N 20' 14.9"
Internet: steve Watt.COM Whois: SW32
Free time? There's no such thing. It just comes in varying prices...