0

If a pthread spawns other pthreads and the scope of the spawned threads is set to PTHREAD_SCOPE_PROCESS, will the spawned threads contend for CPU only with each other or with all threads created within the process/program?

If with all, is there a way to let the spawned threads (or any group of pthreads) contend only with each other?

TuaimiAA
  • 973
  • 6
  • 15
  • They would only compete amongst themselves [of those spawned with the same option]. `PTHREAD_SCOPE_PROCESS` is _not_ implemented on all [many] systems, notably linux. Classically, this is what is called an `LWP`. See my answer: http://stackoverflow.com/questions/39185134/how-are-user-level-threads-scheduled-created-and-how-are-kernel-level-threads-c/39185831#39185831 for details. As a workaround, you might be able to get the same effect by lowering the thread priorities a bit. But, you may want to edit your post to provide some context as to why this would be desirable for you. – Craig Estey Sep 04 '16 at 17:48
  • @CraigEstey Initially, I wanted to use user-level threads to have control of the execution context of a set of tasks (as I am concerned about the cost of context switching and performance). However, the problem of performing context switching in case of blocking I/O led me to explore the idea of using pthreads with a customized scheduling. You may look at my previous question/use case and the comments provided by others: http://stackoverflow.com/questions/39258289/user-level-threads-context-switching-how-to-detect-when-a-thread-is-blocking-in . I would greatly appreciate any suggestions. – TuaimiAA Sep 07 '16 at 01:23
  • If you can edit your question to include more of your [problematic] code, that would help me formulate a better/precise/tailored answer. The short answer: you can't beat native threads for performance. If you're doing excessive context switch, you may need to rearchitect. Also, with I/O, context switch time is relatively minor. BTW, in your other question, one answer mentioned GNU `pth`--That is what I was calling `LWP`. I have extensive experience with threads in commercial products and used `pth` before `NPTL` was available. And, I have multiple posts on multithread performance on SO. – Craig Estey Sep 07 '16 at 02:24

0 Answers0