No CV – the naive approach

One might recall that the exit status of a thread (via pthread_exit(3)) is passed back to the thread that calls pthread_join(3); could we make use of this feature? Well, no: for one thing, it's not necessarily the case that thread B will terminate once the designated work is complete (it might only be a milestone and not all of the job it has to perform), and two, even if it does terminate, perhaps some other thread besides the one invoking pthread_join(3) might need to know.

Okay; why not have thread A poll upon the completion by the simple technique of having thread B set a global integer (call it gWorkDone) to 1 when the work is complete (and having thread A poll on it, of course), perhaps something like the ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.