In a multi-threaded program I need to allocate shared memory based on the estimate computed in parallel by threads and then use that shared memory across all threads (after synchronization). Is there a way to do so without joining the threads and spawning new threads ?
To simplify I am trying to do as below:
- 16 threads estimate the size of memory required in parallel
- Declare the shared memory of estimated size
- Threads continue their execution on the shared memory
I am using pthreads
library and pthread_barrier_wait
for multi-threading.