| 32 | TestThread(int myRank_) : myRank(myRank_) {} |
| 33 | |
| 34 | void run(void) |
| 35 | { |
| 36 | try |
| 37 | { |
| 38 | switch(myRank) |
| 39 | { |
| 40 | case 1: |
| 41 | printf("\nGreetings from thread %d (ID %lu)\n", myRank, threadID); |
| 42 | printf("Unlocking thread 2\n"); |
| 43 | fflush(stdout); |
| 44 | sleep(2); |
| 45 | event.signal(); |
| 46 | break; |
| 47 | case 2: |
| 48 | event.wait(); |
| 49 | printf("\nThread 2 unlocked\n"); |
| 50 | printf("Greetings from thread %d (ID %lu)\n", myRank, threadID); |
| 51 | fflush(stdout); |
| 52 | event.signal(); |
| 53 | sleep(2); |
| 54 | printf("\n2: Releasing two threads.\n"); |
| 55 | fflush(stdout); |
| 56 | sem.post(); sem.post(); |
| 57 | sleep(2); |
| 58 | printf("\n2: Releasing a third thread.\n"); |
| 59 | fflush(stdout); |
| 60 | sem.post(); |
| 61 | break; |
| 62 | case 3: case 4: case 5: |
| 63 | sem.wait(); |
| 64 | printf("Greetings from thread %d (ID %lu)\n", myRank, threadID); |
| 65 | fflush(stdout); |
| 66 | break; |
| 67 | } |
| 68 | } |
| 69 | catch(std::exception &e) |
| 70 | { |
| 71 | printf("Error in %s (Thread %d):\n%s\n", GET_METHOD(e), myRank, |
| 72 | e.what()); |
| 73 | } |
| 74 | if(myRank == 5) THROW("Error test"); |
| 75 | } |
| 76 | |
| 77 | private: |
| 78 | |