I have a pretty specific question about parallel programming in C. I have done quite a bit of research on this, but have seen some conflicting answers, so I hope for some clarification. I have a program, something like the following (sorry for the long block of code):
typedef struct {
pthread_mutex_t mutex;
int eventCounter;
} SharedData;
SharedData globalSharedData;
typedef struct {
} NewData;
void newData(NewData data) {
int localCopyOfCounter;
if () {
pthread_mutex_lock(&globalSharedData.mutex);
localCopyOfCounter = ++globalSharedData.eventCounter;
pthread_mutex_unlock(&globalSharedData.mutex);
}
else {
return;
}
if (localCopyOfCounter != globalSharedData.eventCounter) {
return;
}
if (localCopyOfCounter != globalSharedData.eventCounter) {
return;
}
}
, , newData. , , , : , , CPU, , . , ( , , , , ). eventCounter SharedData , - ? ?