Saturday, May 15, 2010

Exercise 10

1. Find definitions for eight terms and concepts used in threaded programming:


  1. Thread Synchronisation - a process to coordinate execution of threads (Lundh, 2007)
  2. Locks - make sure that two processes do not get into each other's way when accessing a common resource (Eustace, 2010)
  3. Deadlock - two processes are each waiting for the other to complete before proceeding (Webopedia.com, 2010).
  4. Semaphores - a more advanced lock mechanism with an internal counter which will only blocks when the counter reaches to a given number (Lundh, 2007).
  5. Mutex (mutual exclusion) - a program object which allows threads to share the same resources, but not simultaneously (Webopedia.com, 2010).
  6. Thread - a flow of control through the process, plus a private stack for local data (Eustace, 2010).
  7. Event - an action or occurrence detected by a program (Webopedia.com, 2010).
  8. Waitable timer - a synchronization object whose state is set to signaled when the specified due time arrives (Microsoft.com, 2010).

2. A simple demonstration of the threading module in Python (threaddemo.py) 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.

Findings from the codes are:-

1. There are 10 tasks (threads) to run. Start from 0 to 9
2. Only 3 out of 10 can be run at the same time (control by Semaphores - sema)
3. Each task will randomly run from 0 to 2 seconds.
4. There is a read lock (mutex - running counter).

Findings from the output are:-

1. Each thread gets its running time at the beginning (not before starting the thread)
2. Threads start according to its order (0 to 9)
3. Threads end according to its life cycle not order (random time).
4. There are at most 3 threads running at the same time.

No comments:

Post a Comment