In Win32, you can create a thread in suspended mode, by using the dwCreationFlags parameter with CREATE_SUSPENDED. I am looking for a similar functionality with pthreads. Note that I don’t want to suspend the thread after running it and then pausing it by using condition variables, but actually create it in suspended mode and then start it later on.
The advantage of using this approach is that I can assign some properties to that thread before running it. For example, bind it to a certain core before starting, which is more efficient than first starting and then assigning it to a core, as it might get moved from one core to another.
If not possible, can we at least bind a thread to a core when calling pthread_create?
If you want to bind a thread to a CPU right from the start, you can use the form of
pthread_createwith apthread_attr_targument. Linux suports a special attribute pthread_attr_setaffinity_np, which allows the binding of a thread to a certain CPU set. Do not confuse this withpthread_setaffinity_npwhich requires an already running thread.The plan of action is this: