简体   繁体   中英

How long after pthread_exit() can pthread_join() be expected to succeed?

I've been tasked with creating a user-level thread library that replicates the functionality of pthread (full disclosure: this is for an OS course). However, I'm unclear as to how pthread_join() and pthread_exit() interact when a thread has already exited.

In particular, the man page states:

The pthread_join() function waits for the thread specified by thread to terminate. If that thread has already terminated, then pthread_join() returns immediately.

Is this a guarantee that even if I create millions of threads their results will be kept available for one join? Otherwise, how long can I expect the result to be kept around?

I'm not looking for advice on how to implement it (that's most of the fun!), I'm just trying to nail down the behavior before I dive in.

There's no time limit, the implementation has to keep around the "return value" as long as the process itself is alive to make it available to a join.

The POSIX definition for pthread_exit simply says:

The pthread_exit() function shall terminate the calling thread and make the value value_ptr available to any successful join with the terminating thread.

Doesn't matter whether the join was initiated before the exit, or years later, or whether there was only one additional thread or hundreds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM