[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: [OT] multithreading problem: how to give control to another
From:       Thiago Macieira <thiagom () wanadoo ! fr>
Date:       2003-05-21 15:38:41
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


Alexander Neundorf wrote:
>Hi,
>
>writing a multithreaded application, I have the following problem: I have a
>thread running, which looks like
>this:
[snip]
>Now my problem is, how can I make sure that really the "main thread" is the
>one which gets the mutex first
>?

You want to use a wait condition. On the thread, you have to unlock the mutex 
then notify the condition. The main thread is sleeping on the wait condition, 
therefore not consuming resources. When the wait condition is notified, the 
main thread resumes execution and atomically locks the mutex.

That way, the child thread will go back to trying to lock the mutex and will 
wait (I'm not sure if it sleeps) until the main thread unlocks it.

-- 
  Thiago Macieira  -  Registered Linux user #65028
   thiagom@mail.com           
    ICQ UIN: 1967141   PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

[Attachment #5 (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic