Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Linux . How to let a Thread sleep for a period of time waiting for an event

Reply
Thread Tools

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

 
 
Douwe
Guest
Posts: n/a
 
      08-20-2003
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
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      08-20-2003
Douwe <(E-Mail Removed)> 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 ((E-Mail Removed)) ---------------------------\
| 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
 
Reply With Quote
 
 
 
 
Randy Howard
Guest
Posts: n/a
 
      08-21-2003
In article <bi0b5r$amt$(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed)
says...
> Douwe <(E-Mail Removed)> 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.

 
Reply With Quote
 
Randy Howard
Guest
Posts: n/a
 
      08-23-2003
In article <bi5tub$2uh$(E-Mail Removed)>, (E-Mail Removed)
says...
> Randy Howard <(E-Mail Removed)> 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=co...amming.threads
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
[gtk+thread] Why worker thread never wakes from time.sleep()? Dmitry Teslenko Python 0 01-03-2010 08:07 PM
Waiting without sleeping (Thread.sleep) Lew Java 4 09-09-2008 06:22 PM
Re: Waiting without sleeping (Thread.sleep) Joshua Cranmer Java 2 09-09-2008 12:52 PM
What is the difference between Thread.sleep(10) and Thread.currentThread().sleep(10) ? Gonzalo Moreno Java 2 04-05-2004 05:41 PM



Advertisments