Reputation: 1527
The specs say the function "MUST NOT block waiting for the thread or processes to finish. In other words, typically,function() will return before the child processes and the worker thread have completed." How can I accomplish that? Saying pthread_join makes the function wait for the pthread to end, and without it, the thread is cancelled before it does all the work.
Thanks.
Upvotes: 0
Views: 165
Reputation: 69967
To me this sounds like you will have to store a reference to the thread in a container of threads, which is either global or returned by the function and kept by the caller. Then, at the very end of your process (but possibly longer after your function has returned), you call pthread_join
on all threads in that container to ensure they are properly finished.
Upvotes: 2