Re: Understanding NSPR threads
"Wan-Teh Chang" <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.nspr |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Jul 22, 2008 at 7:58 AM, Joachim Ziegler <[email protected]> wrote: > Hello, > > I have read very carefully "Chapter 3, Threads" in the online > documentation, but I must admit that I have a hard time understanding > the API. First of all I do not exactly understand the distinction between > > PR_LOCAL_THREAD > A local thread, scheduled locally by NSPR within the process. > > PR_GLOBAL_THREAD > A global thread, scheduled by the host OS. > > PR_GLOBAL_BOUND_THREAD > A global bound (kernel) thread, scheduled by the host OS > > Can some kind soul explain to me what this means in terms of Unix/Linux > pthreads? What is a "global bound kernel thread"? I suggest that you just use PR_GLOBAL_THREAD. NSPR's terminology here is unfortunately incorrect. PR_LOCAL_THREAD is a user-level thread scheduled by NSPR itself. Here "local" means such threads contend for CPU time within the same process (locally), as opposed to globally with the threads in other processes. PR_GLOBAL_THREAD is the one that is unfortunately misnamed. PR_GLOBAL_THREAD does not mean a "global thread". It means a native thread, which may be a local or global thread. Because of this misnaming, we had to add PR_GLOBAL_BOUND_THREAD to let our users request specifically a global thread. The name "BOUND" came from the old Solaris thread API, which calls global threads "bound threads". Note that the two-level thread scheduling is going out of fashion. These days all the native thread libraries offer global threads only. Global threads are scheduled by the kernel and contend for CPU time globally with the threads in the other processes. In summary, you should just use PR_GLOBAL_THREAD. It means "give me a native thread, I don't care whether it is a local thread or global thread". > IMHO, the whole chapter seriously needs revision, and I am willing to > read through it again and give my comments (in case that someone is > interested). I agree. Thank you for your help! Wan-Teh