| 192 | verbose_print("tasks done") |
| 193 | |
| 194 | def task2(self, ident): |
| 195 | for i in range(NUMTRIPS): |
| 196 | if ident == 0: |
| 197 | # give it a good chance to enter the next |
| 198 | # barrier before the others are all out |
| 199 | # of the current one |
| 200 | delay = 0 |
| 201 | else: |
| 202 | with self.random_mutex: |
| 203 | delay = random.random() / 10000.0 |
| 204 | verbose_print("task %s will run for %sus" % |
| 205 | (ident, round(delay * 1e6))) |
| 206 | time.sleep(delay) |
| 207 | verbose_print("task %s entering %s" % (ident, i)) |
| 208 | self.bar.enter() |
| 209 | verbose_print("task %s leaving barrier" % ident) |
| 210 | with self.running_mutex: |
| 211 | self.running -= 1 |
| 212 | # Must release mutex before releasing done, else the main thread can |
| 213 | # exit and set mutex to None as part of global teardown; then |
| 214 | # mutex.release() raises AttributeError. |
| 215 | finished = self.running == 0 |
| 216 | if finished: |
| 217 | self.done_mutex.release() |
| 218 | |
| 219 | class LockTests(lock_tests.LockTests): |
| 220 | locktype = thread.allocate_lock |