Changeset 2306
- Timestamp:
- 03/10/10 08:29:43 (2 years ago)
- Location:
- cobra/trunk/HowTo/370-Threads
- Files:
-
- 2 modified
-
400-MutexSynchronization.cobra (modified) (5 diffs)
-
500-ThreadPool.cobra (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/HowTo/370-Threads/400-MutexSynchronization.cobra
r2278 r2306 57 57 for t in threads, t.start 58 58 59 Thread.sleep( 5000)59 Thread.sleep(2500) 60 60 print 'Releasing Mutex #1' 61 61 _m1.releaseMutex 62 62 63 Thread.sleep( 5000)63 Thread.sleep(2500) 64 64 print 'Releasing Mutex #2' 65 65 _m2.releaseMutex … … 71 71 print 'Thread #1 waits for both Mutex #1 and Mutex #2' 72 72 WaitHandle.waitAll(@[_m1, _m2]) 73 Thread.sleep( 2000)73 Thread.sleep(1000) 74 74 print 'Thread #1 finished, setting Event #1' 75 75 _events[0].set … … 78 78 print 'Thread #2 waits for only Mutex #1' 79 79 _m1.waitOne 80 Thread.sleep( 2000)80 Thread.sleep(1000) 81 81 print 'Thread #2 completed, setting Event #2' 82 82 _events[1].set … … 85 85 print 'Thread #3 waits for either Mutex #1 or Mutex #2' 86 86 WaitHandle.waitAny(@[_m1, _m2]) 87 Thread.sleep( 2000)87 Thread.sleep(1000) 88 88 print 'Thread #3 completed, setting Event #3' 89 89 _events[2].set … … 92 92 print 'Thread #4 waits for only Mutex #2' 93 93 _m2.waitOne 94 Thread.sleep( 2000)94 Thread.sleep(1000) 95 95 print 'Thread #4 completed, setting Event #4' 96 96 _events[3].set -
cobra/trunk/HowTo/370-Threads/500-ThreadPool.cobra
r2278 r2306 69 69 _serviced[hc] += 1 70 70 71 Thread.sleep( 2000) # block for 2 seconds71 Thread.sleep(1000) 72 72 Interlocked.increment(inout _count) 73 73 # if all jobs were completed then set the completed event … … 90 90 print 'The number of threads used has been successfully limited' 91 91 92 limit = 300 # max work items to queue so that we can see distribution amongst the threads92 limit = 150 # max work items to queue so that we can see distribution amongst the threads 93 93 completedEvent = ManualResetEvent(false) 94 94 worker = Worker(limit, completedEvent)



