Posix Threads and select()

Discussion in 'C Programming' started by Richard Cranium, Jan 2, 2008.

  1. Hello,

    I have an interesting problem:

    I've got one thread in my program meant to maintain a timing subsystem
    and to do network I/O. It uses the select() system call to either wait
    for I/O or "time out" and "handle" some arbitrary "event".

    The timeout value for select() is calculated off of a list of "active
    timers" which contains all the necessary information to correctly guess
    when select() needs to wake up again if no network I/O occurs.

    The problem is, though, that my application is multi-threaded and
    there are times where other threads create and destroy timers. When
    this happens I need to break out of my select() in the I/O & timer
    thread, recalulate the timeout value and then go back to sleep.

    Is there a way I can cause a thread to wake up, or does anyone have a
    suggestion as how to work around this?

    Thanks.

    -Richard
     
    Richard Cranium, Jan 2, 2008
    #1
    1. Advertising

  2. In article <2008010214243716807-cisrichard@gmailcom>,
    Richard Cranium <> wrote:
    >I've got one thread in my program meant to maintain a timing subsystem
    >and to do network I/O. It uses the select() system call to either wait
    >for I/O or "time out" and "handle" some arbitrary "event".


    >Is there a way I can cause a thread to wake up, or does anyone have a
    >suggestion as how to work around this?


    The C programming language does not have threads. Any thread
    capabilities you have are the result of system or library
    extensions beyond C. I suggest that you check the
    comp.programming.threads newsgroup.
    --
    "I will speculate that [...] applications [...] could actually see a
    performance boost for most users by going dual-core [...] because it
    is running the adware and spyware that [...] are otherwise slowing
    down the single CPU that user has today" -- Herb Sutter
     
    Walter Roberson, Jan 2, 2008
    #2
    1. Advertising

  3. On Jan 2, 2:24 pm, Richard Cranium <> wrote:
    > Hello,
    >
    > I have an interesting problem:
    >
    > I've got one thread in my program meant to maintain a timing subsystem
    > and to do network I/O.  It uses the select() system call to either wait
    > for I/O or "time out" and "handle" some arbitrary "event".
    >
    > The timeout value for select() is calculated off of a list of "active
    > timers" which contains all the necessary information to correctly guess
    > when select() needs to wake up again if no network I/O occurs.
    >
    > The problem is, though, that my application is multi-threaded  and
    > there are times where other threads create and destroy timers.  When
    > this happens I need to break out of my select() in the I/O & timer
    > thread, recalulate the timeout value and then go back to sleep.
    >
    > Is there a way I can cause a thread to wake up, or does anyone have a
    > suggestion as how to work around this?
    >
    > Thanks.
    >
    > -Richard


    Richard,

    I would recommend you to re-think about your design since you have
    threads instantiating timers and destroying them.
    It would be best if you could create a module which would keep track
    of the ticks and use that. Thus everybody can access this module to
    get their job done. Even if the thread dies you are not dependent on
    it as the timer module is not killed.

    Good luck,
    Suresh M. Shenoy
     
    suresh shenoy, Jan 2, 2008
    #3
    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. Evan David Light
    Replies:
    6
    Views:
    480
    David Anderson
    Dec 1, 2003
  2. Heiko Neuhaus

    POSIX Threads causing memory leak

    Heiko Neuhaus, Dec 21, 2003, in forum: C++
    Replies:
    3
    Views:
    2,583
    Paul Pluzhnikov
    Dec 21, 2003
  3. Chaman Singh

    STL map and Posix Threads

    Chaman Singh, Apr 8, 2004, in forum: C++
    Replies:
    3
    Views:
    552
    Nick Hounsome
    Apr 9, 2004
  4. Christian Buckl
    Replies:
    6
    Views:
    707
    Alf P. Steinbach
    Oct 8, 2004
  5. JackC
    Replies:
    14
    Views:
    651
    James Kanze
    Oct 16, 2007
Loading...

Share This Page