I've written a "solution" to the producer-consumer/bounded-buffer problem using pthreads, and I use a 72 bit struct to store the data and synchronization types which are shared by all of the threads. This struct is allocated on the heap, but allocating it on the stack and passing its address in pthread_create
also works. Is there any reason to prefer stack allocation over heap allocation (or vice versa) of pthread arguments in cases where pthread_detach
is not used?
Edit:
The struct is declared within main()
, and all threads are guaranteed to finish before main()
is finished. Going out of scope is not an issue.