Reputation: 11
Greetings from 42Urduliz!
I'm currently doing the philosophers project, which is basically 42's take on the classic Dining philosophers problem.
The implementation per se is not relevant for the question, but it's enough to say that each philosopher is a single thread (created with pthread_create) and flow is managed through mutexes.
Now, the question is: is there a 1:1 relationship between threads and the computer's cores? Does the number of threads that can truly run simultaneously equal the number of logical (or physical?) cores available on the machine?
Hope the question makes sense.
Upvotes: 1
Views: 290
Reputation: 37248
There's not a 1:1 relationship between OS threads and logical/physical cores. A typical implementation, say the Linux kernel, will schedule runnable threads on available execution resources (logical/physical cores, hardware threads or whatever you wish to call it). The number of OS threads that an OS can support depends mostly on available memory and OS internal data structures. On typical PC hardware, Linux can easily support tens of thousands of OS threads.
But yes, if the number of runnable OS threads is less than or equal to the number of hardware threads, all of them can run truly simultaneously.
Upvotes: 3