Tuesday, April 28, 2009

Exercise 18: Threading demonstration in Python

A simple demonstration of the threading module in Python that uses both a lock and semaphore to control concurrency is by Ted Herman at the University of Iowa. The code and sample output below are worth a look. Report your findings.

I download the threaddemo.py from the CSU Website and run it in my Mac. Three samples result in my computer:

I ran the program for several times, the results are similar but different. The time taken for each running of the program are slightly different. The running time of 10 tasks thread are different by system generated randomly. The program only allow 3 tasks running concurrently. When a task completed, another task will start. The tasks running like a jobs queue in FIFO model.

No comments:

Post a Comment