linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: Linux c programming list <linux-c-programming@vger.kernel.org>
Subject: Re: linux and pthread
Date: Thu, 11 Nov 2004 09:18:57 +0100	[thread overview]
Message-ID: <20041111081857.GL10443@lug-owl.de> (raw)
In-Reply-To: <419273DC.3050208@bic.mni.mcgill.ca>

[-- Attachment #1: Type: text/plain, Size: 1845 bytes --]

On Wed, 2004-11-10 15:02:36 -0500, Simon Drouin <sdrouin@bic.mni.mcgill.ca>
wrote in message <419273DC.3050208@bic.mni.mcgill.ca>:
> Not sure it is the best place to post that. Tell me if you have any 
> other suggestion.

At least, it's appropriate to ask here.

> I'm running Mandrake 10 and developping a C/C++ program using multiple 
> threads. My program has a main thread that manages UI and a second 
> thread is in a loop that continuously grabs data from a serial port. The 
> communication between the 2 threads is controled by a mutex. The 
> grabbing thread holds the mutex for most of the time in its loop. My 

I guess here's the real problem.

> problem is that when the main thread tries to lock the mutex, it is 
> suspended forever,  like if the grabbing thread didn't release the mutex 
> lock for long enough for the main thread to lock it.

Why do you keep the lock locked? Most of the time, mutexes tend to be
unlocked nearly always and only get locked if (eg. for your example) the
serial thread got a byte and queues it in for the UI thread for
displaying/dispatching/whatnot.

Maybe the trick is to actually use a condition here: let the UI thread
(or a new one) just sleep on the condition. If you got a byte, lock a
mutex (if there are other placed that can access your global serial byte
buffer), queue it in, unlock and wake up the thread(s) sleeping in the
condition. Then, all of them (or only the UI thread) can re-display the
buffer state.

MfG, JBG

-- 
Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

      reply	other threads:[~2004-11-11  8:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-10 20:02 linux and pthread Simon Drouin
2004-11-11  8:18 ` Jan-Benedict Glaw [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041111081857.GL10443@lug-owl.de \
    --to=jbglaw@lug-owl.de \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).