Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Threads

  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Threads

    How can i handle a situation described bellow



    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

    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);

  • #2
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    Homework Assignments

    Think about why you would need the methods described in the paper. Read up a bit on them, they are rather common thread methods.
    "To iterate is human, to recurse divine." -L. Peter Deutsch


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •