Suppose I have code like this:
void *my_thread(void *data)
{
while (1) { }
}
void foo_init(struct my_resource *res)
{
pthread_create(&res->tid, NULL, my_thread, res);
}
void foo_exit(void)
{
}
The script looks something like this. When the process is initialized, the function foo_init()is called with a pointer to my allocated resources (the allocation is performed automatically by another function that is not under my control). Inside the function, I create pthreadone that runs in an infinite loop.
After a while, when the process is about to end, the function is called foo_exit(), but this time without a pointer to my resources and, therefore, I can not call pthread_join(), since mine is tidcontained in the structure my_resource.
, , pthreads ? , .
pthread_join()?
.