473,320 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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 ;)
Nov 13 '05 #1
3 12293
Douwe <do***@parkserver.net> 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 (pa*****@cc.helsinki.fi) ---------------------------\
| 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
Nov 13 '05 #2
In article <bi**********@oravannahka.helsinki.fi>, pa*****@cc.helsinki.fi
says...
Douwe <do***@parkserver.net> 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.

Nov 13 '05 #3
In article <bi**********@chessie.cirr.com>, at***@nospam.cyberspace.org
says...
Randy Howard <ra**********@foomegapathdslbar.net> 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
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olivier Parisy | last post by:
Hi, I like to use thread to simplify the handling of independant, blocking tasks. But controling them from a main thread is not always easy to do in a clean way. So I've written some generic...
3
by: Ken Durden | last post by:
Is there a way to measure or ask .NET to tell me what amount of time a thread spent actually executing on the CPU? For example, I may spawn a thread that spends 99.9% of its time waiting for an...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
6
by: Daniel | last post by:
i have an array that i want all threads to be able to READ from concurrently, however, at times i want to UPDATE the array. at which point i want all threads that use it to block when they try to...
1
by: Matthijs | last post by:
Hi, I have a problem coding a UDP Server/client. The server needs to send big amounts of data over UDP. The problem however is that you can't send as fast as you like. (All packets will be dropped...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
11
by: mark | last post by:
Right now I have a thread that sleeps for sometime and check if an event has happened and go back to sleep. Now instead I want the thread to sleep until the event has occured process the event and...
11
by: Jon Slaughter | last post by:
Is there any way to start a terminated thread without using a pool or creating a new thread object? void counter() { clicks = 0; clock.Start(); while (counterActive) { clicks++;
15
by: suga.masanobu | last post by:
Hello group. I have thread in which I perform specific task in loop. I can specify, by check box, in what periods of time that task should be done, ex. instantly, with 5min break, with 15min...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.