0
What to pass to thread for dynamic memory
Hello I came across a question about thread and heap memory : What should be passed to thread function ? 1. shared pointer 2. Raw pointer 3. Shared pointer with reference 4. Any other better choice
2 Answers
+ 1
Generally it is good to avoid anything shared when working with threads, unless the shared resource is carefully guarded to prevent race conditions and gridlock. I cast my vote for "2. raw pointer" so the thread may own the allocated memory exclusively.
0
Thanks.... AFIK, heap is not safe across the threads.... stack is threadsafe but not heap...
So , is it not safe either we pass it as shared or raw... correct or Am i missing something ?