Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since <code>pthread</code>s do not need to be implemented with Linux threads (or kernel threads at all, for that matter), and some implementations are entirely user-level or mixed, the <code>pthread</code>s interface does not provide functions to access these implementation details, as those would not be portable (even across <code>pthread</code>s implementations on Linux). Thread libraries that use those could provide this as an extension, but there do not seem to be any that do.</p> <p>Other than accessing internal data structures of the threading library (which you understandably do not want, although with your assumptions about processor affinity and Linux thread IDs, your code will not be portable anyway), you may be able to play a trick at creation time, if you control the code that creates the threads:</p> <p>Give <code>pthread_create()</code> an entry function that calls <code>gettid()</code> (which by the way you are likely to have to do using the <code>syscall</code> macro directly because it is not always exported by <code>libc</code>), stores the result somewhere, and then calls the original entry function. If you have multiple threads with the same entry function, you can pass an incremented pointer into an array in the <code>arg</code> argument to <code>pthread_create</code>, which will then be passed to the entry function you created to store the thread ID in. Store the <code>pthread_t</code> return value of <code>pthread_create</code> in the same order, and then you will be able to look up the Linux thread IDs of all threads you created given their <code>pthread_t</code> value.</p> <p>Whether this trick is worth it, depends on how important setting the CPU affinity is in your case, versus not accessing internal structures of the thread library or depending on a thread library that provides <code>pthread_setaffinity_np</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload