473,797 Members | 3,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5165
In article <8f************ *************** *******@h17g200 0prg.googlegrou ps.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.programmin g.threads.

--
Keith Thompson (The_Other_Keit h) 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
1633
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
3629
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 in the cross-reference table to the values table, call them company and state. it's a transitive closure. along the way, naturally, more columns have been added, call them region and division. so that now, the unique identifier from the...
9
1356
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 these options, too. I, for example, prefer to write code using indented braces, like: byte x() {byte i=1;
0
1727
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 AppDomains. I use a static member to count class instance like this, public __gc class foo: public IDisposable { public:
4
2758
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 - similar to "welcome back, Jim" after Jim logs in) and consumed across multiple pages. This "per user" data lives in a database, so toward improving runtime performance I want to cache data supporting this and similar per user features. Because the...
6
2139
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 sites,at that time i want to get the inforamtion and i ahve do some operations.How can i implement this requirement? or What classes are supported in C#.Net? .Please give your suggestion.This requirement is very urgent. thanks in advance,...
8
3949
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 item instead of the usual two (next and prev). Assume that all pointer values can be interpreted as k-bit integers, and define np to be np = next XOR prev, the k-bit "exclusive-or" of next and prev. (The value NIL is represented by
2
2573
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 horribly stuck on even how I actually could write it. Has somebody done that before? And when yes, how is the best way to implement it? Thanks, Thomas
139
14242
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
9537
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10246
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10209
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7560
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3750
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.