- 论坛徽章:
- 3
|
原帖由 zhaoyuaini 于 2008-8-6 10:01 发表
我使用的是kernel_thread开辟的线程,所以是线程,我的问题也是该线程是否能和主线程同时并行,请赐教。
用的是2.6.18内核
Linux的线程被称作轻量级进程,实际上内核对线程的调度跟普通进程的调度是没有什么差别的,正如我前面说到的。只是,线程之间共享了比父子进程更多资源而已。下面这段话我没有翻译,限于本人的英语水平,我想LZ看完应该比较清楚了。
LinuxThreads follows the so-called "one-to-one" model: each thread is actually a separate process in the kernel. The kernel scheduler takes care of scheduling the threads, just like it schedules regular processes. The threads are created with the Linux clone() system call, which is a generalization of fork() allowing the new process to share the memory space, file descriptors, and signal handlers of the parent.
Advantages of the "one-to-one" model include:
* minimal overhead on CPU-intensive multiprocessing (with about one thread per processor);
* minimal overhead on I/O operations;
* a simple and robust implementation (the kernel scheduler does most of the hard work for us).
The main disadvantage is more expensive context switches on mutex and condition operations, which must go through the kernel. This is mitigated by the fact that context switches in the Linux kernel are pretty efficient. |
|