KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I was reading this: http://en.wikipedia.org/wiki/Thread_safety Is the following function thread-safe? void foo(int y){ int * x = new int[50]; /*...do some stuff with the allocated memory...*/ delete [] x; } In the article it says that to be thread-safe you can only use variables from the stack. Really? Why? Wouldn't subsequent calls of the above function allocate memory elsewhere? Edit: Ah. Looks like I misread this part of the article: A subroutine is reentrant, and thus thread-safe, if the only variables it uses are from the stack (I took it to mean A subroutine is reentrant, and thus thread-safe, if and only if the only variables it uses are from the stack , which according to the answers below, is not the case)
Tags (comma-separated)
Save Edits
Cancel