Posix Threads and select()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Cranium

    Posix Threads and select()

    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

  • Walter Roberson

    #2
    Re: Posix Threads and select()

    In article <20080102142437 16807-cisrichard@gmai lcom>,
    Richard Cranium <cisrichard@gma il.comwrote:
    >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.programmin g.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

    Comment

    • suresh shenoy

      #3
      Re: Posix Threads and select()

      On Jan 2, 2:24 pm, Richard Cranium <cisrich...@gma il.comwrote:
      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

      Comment

      Working...