I'm writing a program that uses the POSIX thread library. I'm performing some return value of system calls, such as:
if (pthread_join(temp, NULL) != 0) {
cerr << "system error\n" << endl;
exit(1);
}
I want the program to exit immediately when it passes this if condition, but there could be a problem when the cpu decides to switch to a different thread right before the 'exit(1)' command.
Is there a way to protect such cases?
using a special mutex for this wouldn't help because:
1. i have many calls like this and locking each would make the code very slow, inefficient, and mostly - very ugly!
2. Each mutex requires its own return value check! So that obviously doesn't solve the initial problem..
Any helping ideas?