473,405 Members | 2,160 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,405 software developers and data experts.

how to implement per-thread timer in a multi-thread program?

I want to build a timer for each thread, and the timer must be thread-
safe. How to do that?

My environment is Linux and Pthread.

Thanks.
Jul 28 '08 #1
4 5114
In article <8f**********************************@h17g2000prg. googlegroups.com>,
liu yang <li******@gmail.comwrote:
>I want to build a timer for each thread, and the timer must be thread-
safe. How to do that?

My environment is Linux and Pthread.

Thanks.
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

--
Useful clc-related links:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language

Jul 28 '08 #2
On 28 Jul, 07:56, liu yang <liudo...@gmail.comwrote:
I want to build a timer for each thread, and the timer must be thread-
safe. How to do that?

My environment is Linux and Pthread.
comp.lang.c is for the discussion of standard C (as defined by the ISO
standard). Consequently it does not discuss timers or threads. You
ned to look in a thread or platform (OS) specific group for more
information.

--
Nick Keighley

Jul 28 '08 #3
liu yang <li******@gmail.comwrites:
I want to build a timer for each thread, and the timer must be thread-
safe. How to do that?

My environment is Linux and Pthread.
Try a Linux newsgroup or comp.programming.threads.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 28 '08 #4
On 28 Jul 2008 at 6:56, liu yang wrote:
I want to build a timer for each thread, and the timer must be thread-
safe. How to do that?

My environment is Linux and Pthread.
Unfortunately, there is no way to get POSIX alarms to signal a calling
thread specifically. So you'll need to do some manual coding around it.

You can set up a thread to deal with the alarms. It blocks all signals
except that it sets up a handler for SIGALRM, then enters a sigwait()
loop.

When another thread wants to receive that alarm, it sets up a handler
for SIGUSR1 (say), and calls a function you provide that registers that
thread with your waiting thread.

When the process is sent a SIGALRM, the waiting thread returns from
sigwait(), works out which thread it should send the alarm to, and sends
a SIGUSR1 to that thread.

Of course you need to be quite careful to keep track of which thread
asked for an alarm at what time, and reset the alarm when necessary.

Jul 28 '08 #5

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

Similar topics

4
by: siliconmike | last post by:
Hello, I'd like to implement a large 2-d array 2d array size: 5000 x 5000 each element: int 4 bytes type: static, MYISAM how is this done in MySQL? I'm a newbie, so details will help. Mike
4
by: robert | last post by:
before i go flapping my gums and get deeper in alligators, wondering whether the following makes sense. i have a database which provides picklists for input. it started out with a 2 column key...
9
by: Axel Dahmen | last post by:
I've just read about the new Whidbey, which I think gives great features to the programmer. The HTML editor comes with a bunch of great formatting options. It'd be great if C# would get some of...
0
by: Tony Wong | last post by:
I am trying to implement the Singleton Pattern for a assembly (class) which control a common resource on my computer. I need the Singleton behavior within a single process which contain multiple...
4
by: Guadala Harry | last post by:
Is there any way for one Session to remove and update objects in another Session? I seriously doubt it, but thought I'd ask. Here's why: I have some data that is unique per user (or per session -...
6
by: TulasiKumar | last post by:
hi all, i have one requirement in my project.The requirement is i want to fix some domain sites in TcpIp like proxy servers behaviour.When ever end user passing the inforamtion of that domain...
8
by: tonywinslow1986 | last post by:
I'm reading MIT's book "Introduction to Algorithms". The following is one of the excercises from it: < 10.2-8 Explain how to implement doubly linked lists using only one pointer value np per...
2
by: Thomas Ploch | last post by:
Hello folks, I am having troubles with implementing a timed queue. I am using the 'Queue' module to manage several queues. But I want a timed access, i.e. only 2 fetches per second max. I am...
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.