I am trying to achieve the following:
Force the newly created thread to start running, immediately after pthread_create()
. No real-time scheduling is being used.
From the pthread_create() man page:
Unless real-time scheduling policies are being employed, after a call to pthread_create(), it is indeterminate which thread—the caller or the new thread—will next execute.
Which of course makes sense. Thus, I thought by using pthread_yield()
I would force the newly created thread to take over and as a result start. But this is not the case.
I could only achieve the desired result by sleeping after the pthread_create()
. But I don't want to rely on this solution atm.
- Why can't I achieve my goal with
pthread_yield()
? - Is there some other way than using sleep?
- The creation of new threads is handled the same way as task-switching, i.e. follows the scheduling policy? For example, in RT (preemptive) scheduling, if the newly created thread has a higher priority, will it immediately preempt the current thread?
Related post:
- Does pthread_create starting thread?
- pthread_mutex not updating fast enough, so one thread "hogs" the lock.
Thanks!
pthread_create()
until the new thread signals the creator thread. – Iharob Al Asimipthread_yield()
approach is not working for me. @terence the thread that is callingpthread_create()
is also callingpthread_yield()
. – Tanasis