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

D

Douwe

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 ;)
 
J

Joona I Palaste

Douwe said:
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 ???

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

--
/-- Joona Palaste ([email protected]) ---------------------------\
| 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
 
R

Randy Howard

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.
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top