Re: Wait for flag

From: Martin James (mjames_falcon_at_dial.pipex.com)
Date: 11/05/03


Date: Wed, 5 Nov 2003 14:31:02 -0000


"maccor.com>" <j.munk@<remove this> wrote in message
news:3fa90609$1@newsgroups.borland.com...
> How do I most efficiently let the main thread of an application to wait
for
> another thread to raise a flag (to signal that data are ready)? Right now
I
> just loop until the flag (a byte) is set or a time out reached, but just
> spinning a loop takes a lot of system resources although it is typically
not
> for much longer than 50ms at the time.

Post a message to fire a message-handler event. Main-thread event handlers
should not wait. If you have a need to wait, you need to change your design
to be event-driven.

> Another way to do it could be to suspend the main thread for e.g. 40ms,
but
> although you can suspend threads you have created yourself, I don't see
how
> you can suspend the main (i.e. application thread)

Well, you *could* suspend it, but I wouldn't recommend it. The main thread
should be handling the GUI, not polling threads.

> FYI, what I need it for is to communicate between two applications on two
> computers (one cound be embeded), so I send out a request for data and
then
> I wait until I get the data received event.

Two computers? What are you using to communicate between them? IP/sockets?
Some shared bus?

Need input..

Rgds,
Martin



Relevant Pages

  • Re: SendMessage (in secondary thread) freezes application GUI thre
    ... power left, the application stopped hanging... ... Then, in the non-UI thread, check the flag. ... queue and, again, the third thread will process that. ... will probably suspend before the about-to-suspend message gets to the UI ...
    (microsoft.public.windowsce.app.development)
  • Re: SendMessage (in secondary thread) freezes application GUI thre
    ... Then, in the non-UI thread, check the flag. ... queue and, again, the third thread will process that. ... If the system is about to go into suspend mode, ... will probably suspend before the about-to-suspend message gets to the UI ...
    (microsoft.public.windowsce.app.development)
  • [PATCH 2/5] Container Freezer: Make refrigerator always available
    ... The refrigerator() can now be used in a control group subsystem ... The PF_FREEZER_SKIP flag should be set by a vfork parent right before it ... +static inline void frozen_process ... config SUSPEND ...
    (Linux-Kernel)
  • Re: [PATCH] pata_sil680 suspend/resume
    ... Jeff submitted the respective cumulative libata patch last ... ATA_DFLAG_SUSPENDED flag? ... "disk" be suspended before the host and is it when the eh should set the ... Shall I suspend it explicitely from userspace? ...
    (Linux-Kernel)
  • Re: Question on mmap() in 64-bit OS
    ... user when calling mmap() with the MAP_FIXED flag on in a 64-bit Linux ... It will be one hell of a long time before computers have that ... serve a number of different purposes. ...
    (comp.os.linux.development.system)