C force the thread to start immediately after pthread_create. pthread_yield after pthread_create?
<p>I am trying to achieve the following: </p>

<p>Force the newly created thread to start running, immediately after <code>pthread_create()</code>. No real-time scheduling is being used.</p>

<p>From the <a href="http://man7.org/linux/man-pages/man3/pthread_create.3.html" rel="nofollow noreferrer">pthread_create() man page</a>:</p>

<blockquote>
  <p>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.</p>
</blockquote>

<p>Which of course makes sense. Thus, I thought by using <code>pthread_yield()</code> I would <em>force</em> the newly created thread to take over and as a result start. But this is not the case.</p>

<p>I could only achieve the desired result by <em>sleeping</em> after the <code>pthread_create()</code>. But I don't want to rely on this solution atm.</p>

<ol>
<li>Why can't I achieve my goal with <code>pthread_yield()</code>?</li>
<li>Is there some other way than using sleep?</li>
<li>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?</li>
</ol>

<p>Related post:</p>

<ul>
<li><a href="https://stackoverflow.com/questions/23051676/does-pthread-create-starting-thread">Does pthread_create starting thread?</a></li>
<li><a href="https://stackoverflow.com/questions/16138072/pthread-mutex-not-updating-fast-enough-so-one-thread-hogs-the-lock">pthread_mutex not updating fast enough, so one thread &quot;hogs&quot; the lock.</a></li>
</ul>

<p>Thanks!</p>