views:

56

answers:

1

Hello, World!

I would like to know if it is possible to identify physical processor (core) is used by thread with specific thread-id?

For example, I have an multithreaded application that has 2 threads (threadid = 10 and threadid = 20, for instance). I run the application on a system that has a dual core processor (core 1 and core 2). So, how to get to know number of core is used by thread with threadid = 20?

P.S. Windows platforms.

Thank you,

Denis.

+2  A: 

Unless you use thread-affinity, threads are not assigned to specific cores. With every time slice, the thread can be executed on different cores. This means that if there would be a function to get the core of a thread, by the time you get the return value, there's a big chance that the thread is already executing on another core.

If you are using thread-affinity, you could take a look at the Windows thread-affinity functions (http://msdn.microsoft.com/en-us/library/ms684847%28v=VS.85%29.aspx).

Patrick
Thank you for your response, Patrick! So another question is appeared - is it possible to get to know how much time a specific thread runs on specific core? (for example some thread runs 20% of its time slice on core 1 and 80% of its time slice runs on core 2)
Denis
Not that I'm aware of Denis. What you can do is limit a thread to specific cores (this is called thread-affinity). Maybe you can split up your process in multiple threads where each thread is assigned to one core. Can you explain what the original problem is? (leading to your original question) Maybe your problem can be solved in another way.
Patrick
I've been tasked to create two functions: 1. The first function returns total multicore processor usage by specific thread id. I've implemented the function using Performance Counter Functions.2. The second function returns specific core usage by specific thread id. I have no idea how to create the function, it seems it is impossible.
Denis
I also think this is impossible.
Patrick