简体   繁体   中英

Pthreads - main thread and other thread

In Pthreads, when we create multiple threads inside the main function, does all the created threads become a worker thread for the main thread? or each thread is a manager thread by itself?

when we create multiple threads inside the main function, does all the created threads become a worker thread for the main thread?

Worker/main thread designation is conceptual.

There's no Pthreads designated thread that manages all the other worker threads. Typically, main thread is used for that job. But nothing prevents you from choosing another thread to manage all the threads. Main thread can also participate in the the "work" as a worker.

each thread is a manager thread by itself?

A thread is an independent entity within a process. Usually, they all "co-ordinate" with each other to accomplish a common goal. But you can also have multiple groups of threads, with each group doing different tasks. So there doesn't necessarily have to be a "manager thread". Because a thread can be completely independent and exit (pthread_exit) without ever needing to communicate with others (eg Each thread sorting a separate file). Or the threads may co-ordinate with each other (eg matrix multiplication). Or they may be "managed" by a one thread (eg main thread "feeding" work to others in queue which will be worked on by other threads in a master/slaves manner).

When you create a thread, you can call it a "worker" if you want. The thread doesn't care how people think about it. It runs the same whether you call it a "worker", "manager", or "moose" for all it matters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM