Monday, May 11, 2009

Exercise 18: Threading demostration in Python

Source Code of the threaddemo.py


Process Explain:
In this demo, the first part is defining the objects, variables and values.

The second part defining the common variable which will be access by the threads.
The third part is the major part of the threaddemo.
During the main program runs, the program acquire the lock for the the common variable and add a value into it. A delay of a random time is started just after the release of the common variable. At this moment, the other thread can be created by the main program. After the delay is end, the thread acquire the lock again and reduce the variable for the number of running processes.

Findings:
According to the result provided with the exercise, the longer the wait time o the thread, the later end of the process. This program favor the smaller program. The smaller thread uses the waiting time of the long waited thread to get its job done. Thread in this program simulate the multi-tasking environment to a common resources.

No comments:

Post a Comment