Posix Threads and select()

  • Thread starter Richard Cranium
  • Start date
R

Richard Cranium

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
 
W

Walter Roberson

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.
 
S

suresh shenoy

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top