1319static int data1Value = 0;
1320static int data2Value = 0;
1321pthread_mutex_t *data1Lock;
1322pthread_mutex_t *data2Lock;
1323void lock(pthread_mutex_t *);
1324void unlock(pthread_mutex_t *);
1325void *funcA(void *param) {
1326 pthread_mutex_lock(data1Lock);
1327 data1Value = 1;
1328 pthread_mutex_unlock(data1Lock);
1329 pthread_mutex_lock(data2Lock);
1330 data2Value = data1Value + 1;
1331 pthread_mutex_unlock(data2Lock);
1332 return ((void *)0);
1333}
1334void *funcB(void *param) {
1335 int t1 = -1;
1336 int t2 = -1;
1337 pthread_mutex_lock(data1Lock);
1338 if (data1Value == 0) {
1339 pthread_mutex_unlock(data1Lock);
1340 return ((void *)0);
1341 }
1342 t1 = data1Value;
1343 pthread_mutex_unlock(data1Lock);
1344 pthread_mutex_lock(data2Lock);
1345 t2 = data2Value;
1346 pthread_mutex_unlock(data2Lock);
1347 if (t2 != (t1 + 1)) {
1348 fprintf(stderr, "Bug found!\n");
1349 ERROR: goto ERROR;
1350 ;
1351 }
1352 return ((void *)0);
1353}
1354int main(int argc, char *argv[]) {
1355 int i,err;
1356 if (argc != 1) {
1357 if (argc != 3) {
1358 fprintf(stderr, "./twostage <param1> <param2>\n");
1359 exit(-1);