On Thu, Aug 24, 2000, ������ wrote:
> Hi, my name is Ryu, and I am a newbie to C and am studying about thread.
> I was reading your manuals of pth, and there was 'standard POSIX
> replacements API', 'pth_write', 'pth_sleep', and etc.
>
> You said that these functions would only block that thread not the whole
> process, and there is a example which uses 'pth_' type functions instead
> of using 'write()' or 'sleep()'. My question is why 'read()' will block
> the whole process not the thread which uses 'read()'. Won't 'read()'
> block only that thread? I read a little bit about LinuxThread, and it
> does not seem to indicate anything about 'standard POSIX replacements
> API'.
read(2) is a system call implemented by the Unix kernel. The Unix kernel
knowns nothing about user-land threads inside processes as Pth provides. So if
a system call like read(2) has to wait for an event (here no data available
for reading) the kernel suspends the calling process and consequently all
user-lands threads inside this process. By using pth_read(2) the
suspension of the process by the kernel is avoided and instead Pth's
scheduler suspends only the calling _thread_.
LinuxThreads is special in two cases: First it has no such problem, because
its threads are located in kernel-land (simplified: a LinuxThreads thread is a
Linux process). Second, LinuxThreads is tied into glibc (and this way
non-portable, of course) and this way doesn't have to provide an explicit API
which replaces system calls (instead it can directly hook into the syscall
stubs in libc).
> Another question is about creating a new thread within a thread. After a
> thread is created from 'main(), is it OK to create threads within a
> thread? Thanks.
Yes, sure. You can create threads from within threads.
Ralf S. Engelschall
[EMAIL PROTECTED]
www.engelschall.com
______________________________________________________________________
GNU Portable Threads (Pth) http://www.gnu.org/software/pth/
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager (Majordomo) [EMAIL PROTECTED]