Serialized by the mutex lock : Thread Synchronize « Thread « Python






Serialized by the mutex lock

Serialized by the mutex lock
import thread, time

def counter(myId, count):
    for i in range(count): 
        mutex.acquire()
        print 'thread number %d reporting in at %d...' % (myId, time.clock())
        time.sleep(1)
        mutex.release()

print time.clock()
mutex = thread.allocate_lock()
for i in range(5):
    thread.start_new(counter, (i, 3))

time.sleep(20) 
print 'Main thread exiting.'

           
       








Related examples in the same category

1.Synchronize stdout access to avoid multiple prints on 1 lineSynchronize stdout access to avoid multiple prints on 1 line
2.Uses simple shared global data to know when threads are done in parent/main threadUses simple shared global data to know when threads are done in parent/main thread