English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Requirements: In a particular system there are two threads T1 and T2.
T1 is the master thread that periodically sends messages to the worker thread T2.
The system is time-critical and hence T2 must react to every message that T1 sends.
None of the messages must be lost.T2 performs time consuming operations like say
mixing sound samples and sending them to the sound buffer.

Here is the hypothetical POSIX like library that is available to
synchronize the threads:

Mutex locking and unlocking are done through to the calls
int lock(Mutex_t* mutex);
int unlock(Mutex_t* mutex);

Thread messaging is done through condition variables that operate
with an associated mutex.

A thread that responds to a message needs to wait on a condition variable.
It should own the associated mutex prior to entering the wait state.
When it enters the wait state, it simultaneously releases the ownership
of the mutex. Upon return from the wait state, it owns the mutex.
int wait(Condition_t* condition, Mutex_t* mutex);

A thread that sends message to another thread needs to signal the condition
variable. In order to signal the condition variable, the thread must own the
associated mutex.If no thread is waiting on the condition variable, the `signal'
or message is lost. If a thread is waiting on the condition variable, then it resumes
execution.
int signal(Condition_t* condition, Mutex_t* mutex);

2006-08-24 17:53:10 · 1 answers · asked by bishnu p 1 in Computers & Internet Programming & Design

1 answers

This is covered in great detail in most theory of programming texts. If the professor assigned this as a problem, there's probably enough hints in your textbook to solve this yourself....

Note that the problem isn't well-specified - it says it's "time critical", but then fails to provide you with any of the API you need to deal with this In particular, how do you guarantee that T2 gets sufficient CPU to not fall behind in the requests?

Also, it specifies *two* threads - and then specifically says if nobody is waiting on the condition variable, the signal is lost. This means that if P2 is busy doing something CPU intensive, you just dropped one on the floor. (Such a lack-of-queueing of requests is almost always the *first* thing any thread programmer fixes...

That should be enough hints for you to complete the assignmentt :)

2006-08-24 20:12:22 · answer #1 · answered by Valdis K 6 · 0 0

fedest.com, questions and answers