Canonical way to differentiate between NPTL / Cobalt threads
We're using a mix of regular NPTL posix threads and RT cobalt threads in our application, using XDDP communication between them.
In a few places, we need to identify the calling context, ie, whether we're being called from a cobalt RT thread or from a regular NPTL thread, and act accordingly.
My understanding is that calling pthread_getschedparam and checking that the returned policy is SCHED_FIFO does the job.
* is it correct ? Or are they some corner cases not covered by this test ?
* is it the canonical way, or is there another one ? (maybe cheaper - since this call will do two calls in case of a posix thread, there must be a cheaper way to detect the running context).
Regards,
Julien
Quoted 7 lines · Julien Blanc
We're using a mix of regular NPTL posix threads and RT cobalt threads in our application, using XDDP communication between them.
In a few places, we need to identify the calling context, ie, whether we're being called from a cobalt RT thread or from a regular NPTL thread, and act accordingly.
Quoted 5 lines
My understanding is that calling
pthread_getschedparamand checking that the returned policy isSCHED_FIFOdoes the job.* is it correct ? Or are they some corner cases not covered by this test ?
A regular pthread undergoing the SCHED_FIFO policy would also match this test, so this would work as long as SCHED_FIFO is exclusively used for Cobalt threads.
Quoted 4 lines
* is it the canonical way, or is there another one ? (maybe cheaper - since this call will do two calls in case of a posix thread, there must be a cheaper way to detect the running context).
cobalt_thread_pid(pthread_t) from the internal support library would do the job. A successful call would denote a cobalt thread, -ESRCH would denote a regular (or invalid) pthread.
Signature · 1 line
Philippe.
Le mercredi 28 mars 2018 à 16:16 +0200, Philippe Gerum a écrit :
Quoted 5 lines
cobalt_thread_pid(pthread_t)from the internal support library would do
the job. A successful call would denote a cobalt thread,-ESRCHwould denote a regular (or invalid) pthread.
Seems to work perfectly, thanks.
Regards,
Julien