1

Is there way to get which core is used by the thread?
for example

printf("..., Core: %2d\n", coreN);
HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
Ufx
  • 2,595
  • 12
  • 44
  • 83

2 Answers2

3

If you're using Linux based systems you can use

sched_getcpu() 

to print the current CPU/core number on which the thread is running

cout << "Thread running on Core " << sched_getcpu() <<endl
Daksh Gupta
  • 7,554
  • 2
  • 25
  • 36
0

C++ does not provide a function or anything for achieving this, since there is no notion of core in the language.

You could run a Linux command via a system call to check that out: How can I see which CPU core a thread is running in?

gsamaras
  • 71,951
  • 46
  • 188
  • 305