Create pthread c3/16/2024 ![]() Question : What is the best practice of returning/storing variables of multiple threads? A global hash table? If you absolutely have to use the thread exit value for a structure, then you'll have to dynamically allocate it (and make sure that whoever joins the thread frees it). Pthread_create(&tid, NULL, myThread, &result) ![]() * thread operation might fail, so here's a silly example */ You can (if you like) use the thread exit value to indicate success: #include This then becomes the (only) parameter to the thread's entry-point. The usual way to do this, when the thread that starts is the same thread that joins, would be to pass a pointer to an int, in a location managed by the caller, as the 4th parameter of pthread_create. ![]() ![]() That's bad even if threads aren't involved. You've returned a pointer to a local variable. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |