Sign in to follow this  
wh1sp3rik

windows threads

Recommended Posts

Hello,
I have few questions about threads.

Let's say, i have 4core cpu and i will create 4 threads by CreateThread function.
It will create thread on every my core.

Now, what if i want to create 5. thread ? what core will run this thread ?
I would like to select a core to make a thread on them somehow, is it possible ? becuase i would like to have few cores for max cpu speed. if i create 5. thread, i don't know, which core do multitasking with my 5. thread.

Thank you very much for answers ;-)

Share this post


Link to post
Share on other sites
Quote:
Original post by wh1sp3rik
Let's say, i have 4core cpu and i will create 4 threads by CreateThread function.
It will create thread on every my core.


Not necessarily. It is up to the operating system's scheduler to decide when each thread gets time on a CPU.

Quote:

Now, what if i want to create 5. thread ? what core will run this thread ?

Same answer.

Quote:

I would like to select a core to make a thread on them somehow, is it possible ?


You can pin a thread to a core (using e.g. SetThreadAffinityMask on Windows) but you cannot pin a core to a thread, as that would allow a user-land application to clog up the whole system (a DOS attack). However, even pinning a thread to a core is still reasonably unusual and you should probably avoid it in general. AFAIK, SetThreadAffinityMask is also only a strong hint rather than a decree.

Quote:

becuase i would like to have few cores for max cpu speed. if i create 5. thread, i don't know, which core do multitasking with my 5. thread.

Let the operating system handle the scheduling.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this