hello,
how do i make both threads have access to the same set of updated data, when they call different functions?
in addition, is the way i pass in the variable "myObjs" correct? can i pass in STL containers the same way?
example:
...
class aClass{
...
};
int main(){
void *plus (void *);
void *minus (void *);
pthread_t thread1, thread2;
...
aClass[100] myObjs; // may use STL Containers
retVal1 = pthread_create(&thread1, NULL, plus, (void *) myObjs);
retVal2 = pthread_create(&thread2, NULL, minus, (void *) myObjs);
...
}
...
in this code, thread1 will increase the value of member variables, while thread2 will decrease the value of the member variables... but i need them to be updated.
in addition, when im adding the values, how do i mutex lock the minus function, so it wont add and minus at the same time, and vice versa?
lastly, if i change the code to use STL container, i would edit the function "plus()" to add a new object, and the function "minus()" to erase an object.