Linux . How to let a Thread sleep for a period of time waiting for an event

Discussion in 'C Programming' started by Douwe, Aug 20, 2003.

  1. Douwe

    Douwe Guest

    I'm trying to write a piece of C code that has two threads: The first
    thread waits for a socket connection. The second thread is in a
    continues cycle waiting for an period of time (lets say 500 ms) or an
    incomming socket connection (received from the first thread). At this
    moment I've created two threads were the first one is already waiting
    for an incomming socket connection. I've also created a timer with
    timer_create. My problem is that the second thread has to wait until
    one of the events it is waiting for occurs. For completeness the
    events are : an timer event or a message from the first thread that it
    got an incomming socket connection.

    Do I have to use a Semaphore here ... or do I have to use signals ...
    or how do I solve this ???

    help ;)
     
    Douwe, Aug 20, 2003
    #1
    1. Advertising

  2. Douwe <> scribbled the following:
    > I'm trying to write a piece of C code that has two threads: The first
    > thread waits for a socket connection. The second thread is in a
    > continues cycle waiting for an period of time (lets say 500 ms) or an
    > incomming socket connection (received from the first thread). At this
    > moment I've created two threads were the first one is already waiting
    > for an incomming socket connection. I've also created a timer with
    > timer_create. My problem is that the second thread has to wait until
    > one of the events it is waiting for occurs. For completeness the
    > events are : an timer event or a message from the first thread that it
    > got an incomming socket connection.


    > Do I have to use a Semaphore here ... or do I have to use signals ...
    > or how do I solve this ???


    > help ;)


    Your problem is UNIX-specific and thus off-topic on comp.lang.c. Please
    ask on comp.unix.programmer.

    --
    /-- Joona Palaste () ---------------------------\
    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
    | http://www.helsinki.fi/~palaste W++ B OP+ |
    \----------------------------------------- Finland rules! ------------/
    "Shh! The maestro is decomposing!"
    - Gary Larson
     
    Joona I Palaste, Aug 20, 2003
    #2
    1. Advertising

  3. Douwe

    Randy Howard Guest

    In article <bi0b5r$amt$>,
    says...
    > Douwe <> scribbled the following:
    > > I'm trying to write a piece of C code that has two threads: The first
    > > thread waits for a socket connection. The second thread is in a
    > > continues cycle waiting for an period of time (lets say 500 ms) or an
    > > incomming socket connection (received from the first thread). At this
    > > moment I've created two threads were the first one is already waiting
    > > for an incomming socket connection. I've also created a timer with
    > > timer_create. My problem is that the second thread has to wait until
    > > one of the events it is waiting for occurs. For completeness the
    > > events are : an timer event or a message from the first thread that it
    > > got an incomming socket connection.

    >
    > > Do I have to use a Semaphore here ... or do I have to use signals ...
    > > or how do I solve this ???

    >
    > > help ;)

    >
    > Your problem is UNIX-specific and thus off-topic on comp.lang.c. Please
    > ask on comp.unix.programmer.


    Actually, comp.programming.threads is probably the better forum. POSIX
    pthreads (the variety most likely to be used on Linux) is the primary
    thread model discussed there.

    OT: Lookup condition variables.
     
    Randy Howard, Aug 21, 2003
    #3
  4. Douwe

    Randy Howard Guest

    In article <bi5tub$2uh$>,
    says...
    > Randy Howard <> spoke thus:
    >
    > > Actually, comp.programming.threads is probably the better forum. POSIX
    > > pthreads (the variety most likely to be used on Linux) is the primary
    > > thread model discussed there.

    >
    > Is that the name of it? I'm not seeing it listed on my news server (although
    > it not being carried is certainly a possibility). It certainly sounds
    > interesting.


    That is the correct name. Ask your newsfeed to carry it. Failing that
    you should be able to get to it here:

    http://groups.google.com/groups?q=comp.programming.threads
     
    Randy Howard, Aug 23, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gonzalo Moreno
    Replies:
    2
    Views:
    12,521
  2. Lew
    Replies:
    4
    Views:
    903
  3. Joshua Cranmer
    Replies:
    2
    Views:
    518
    Andrew Thompson
    Sep 9, 2008
  4. Dmitry Teslenko
    Replies:
    0
    Views:
    651
    Dmitry Teslenko
    Jan 3, 2010
  5. Hans Vlems

    waiting period

    Hans Vlems, Jan 25, 2011, in forum: C Programming
    Replies:
    17
    Views:
    568
    Hans Vlems
    Jan 27, 2011
Loading...

Share This Page