pthread_create 會多建立一個 thread 的原因
之前在執行某個客戶的案子時,被問到一個問題:「你說你們程式開了兩個thread,那為什麼透過 ps 指令觀察到的個數卻是 4 個呢?」(ps 的指令為 ps -L ,可以透過 PID 和 LWP 這兩個欄位看出來),一時之間不知道怎麼回答。之後由同事 York 在 man pthreads找到了下面的答案。 Linux implementations of POSIX threads Over time, two threading implementations have been provided by the GNU C library on Linux: LinuxThreads This is the original Pthreads implementation. Since glibc 2.4, this implementation is no longer supported . NPTL (Native POSIX Threads Library) This is the modern Pthreads implementation. By comparison with LinuxThre...