Pthread Unlock and return some value
Nov 24, 2014 at 8:06am UTC
hi,
I want to call to a simple synchronized function and return some value. Is it possible with fallowing code in a multi threaded environment?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int doSomething(int a,int b){
int returnValue = 0;
pthread_mutex_lock(&lock);
// Do something
returnValue = 1;
pthread_mutex_unlock(&lock);
return returnValue;
}
Please explain.
Thank you.
Nov 24, 2014 at 10:09am UTC
What is the mutex "lock" supposed to be protecting? The variable "returnValue"? That's local to each thread. Perhaps there is something more in your actual situation that I am missing?
Nov 24, 2014 at 12:07pm UTC
Hi,
You did not miss anything. I got your idea. It is clarified that "returnValue" is local to each thread. So there are no issue with this function.
Thank you very much.
Topic archived. No new replies allowed.