[SOLVED] Reentrant definition
I don't understand reentrant definition:
what does he means with "each invocation uses its own data"?
Imagine you have a sort() function that sorts a given array of integers. If the function is "reentrant", you can safely call it simultaneously from different threads, but only if each thread passes its own separate array to the function. Calling it multiple times in parallel on the same array would not be safe. Also, if the function was not reentrant, then calling the function simultaneously from different threads would not be safe, even if each thread uses its own separate array. That would be the case, e.g., if the function internally uses global/static variables.
In C++, object functions usually are reentrant, simply because each object (instance) has its own separate member variables, so there are no conflicts, as long as each thread calls the function on its own separate object (instance). But as soon as multiple threads try to call the function on the same object (instance), there will be conflict again, so object functions usually are not tread-safe. Thread-safety requires that all access to member variables is carefully protected by, e.g., Mutexes. Don't assume thread-saftey, unless the docs explicitly state it.
And take care: Object functions still can be non-reentrant, e.g., if static member variables are involved :-/
Ok, thanks, I have well understood :)