1. Find definitions for eight terms and concepts used in threaded programming:
Thread Synchronisation is the methodology of managing concurrently executing threads and control their access to data, memory and code segments.
Locks are a synchronisation mechanism for enforcing limits on access to a resource in an environment where there are many threads of execution.
Deadlock is a situation in which two or more processes or threads sharing the same resource are effectively preventing each other from accessing the resource, resulting in all ceasing to function.
Semaphores are a thread synchronization object that allows zero to any number of threads access simultaneously.
Mutex (mutual exclusion) is the thread synchronization object which allows to access the resource only one thread at a time. Only when a process goes to the signaled state are the other resources allowed to access.
Thread is a single instance of a process
Event is a thread synchronization object used to set the signaled or non-signaled state. The signaled state may be manual or automatic depending on the event declaration.
Waitable timer is a synchronisation object whose state is set to signaled when the specified due time arrives. There are two types of waitable timers that can be created: manual-reset and synchronisation.
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. Report your findings.
The demo is written to:
run 10 threads (count in a variable running)
constrain the number of simultaneous threads to 3 (via a semaphore sema)
threads to run for a random time period of 0-2 seconds (held in a variable delay)
running can only be updated by one thread at at time (controlled by a mutex lock)
This results in:
Threads 1,2,3 are initialised, assigned a delay and started
Threads 4-10 are initialised, assigned a delay and then wait for the semaphore to all them to start
References:
Threaded programming
http://www.codeproject.com/KB/threads/Synchronization.aspx
Saturday, May 29, 2010
Subscribe to:
Post Comments (Atom)


No comments:
Post a Comment