-6

I want to know whether threads created using pthread.hlibrary are using one core, or they are running in multiple cores.

Misho Tek
  • 624
  • 2
  • 11
  • 22
  • 5
    They'll run on as many cores as the OS allows them to. That can be none, one, ..., or even 64 if you have a server CPU. – hnefatl Nov 20 '17 at 18:43
  • 1
    Whatever the underlying (POSIX thread compatible) OS chooses. – Zeta Nov 20 '17 at 18:43
  • @Zeta or not the OS at all, when the pthread implementation is a userspace implementation, which is also possible – Ctx Nov 20 '17 at 18:49
  • 1
    What the above comments are telling you is that `pthreads` is an API. In order to get the answer you are looking for, you'll have to identify a specific _implementation_ of the pthreads API. – Solomon Slow Nov 20 '17 at 19:54

1 Answers1

1

A newly created thread has no affinity, and will be shuffled around the process as deemed best by the system.

If you need to pin it to a specific core, this answer provides details for setting affinity to a specific pthread.

Matt Clark
  • 27,671
  • 19
  • 68
  • 123
  • This answer is only correct for specific environments, i.e. common linux distributions. pthreads can of course be implemented for example as userspace threads, where this is not correct. – Ctx Nov 20 '17 at 18:48