473,809 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Posix Threads and select()

Hello,

I have an interesting problem:

I've got one thread in my program meant to maintain a timing subsystem
and to do network I/O. It uses the select() system call to either wait
for I/O or "time out" and "handle" some arbitrary "event".

The timeout value for select() is calculated off of a list of "active
timers" which contains all the necessary information to correctly guess
when select() needs to wake up again if no network I/O occurs.

The problem is, though, that my application is multi-threaded and
there are times where other threads create and destroy timers. When
this happens I need to break out of my select() in the I/O & timer
thread, recalulate the timeout value and then go back to sleep.

Is there a way I can cause a thread to wake up, or does anyone have a
suggestion as how to work around this?

Thanks.

-Richard

Jan 2 '08 #1
2 3409
In article <20080102142437 16807-cisrichard@gmai lcom>,
Richard Cranium <ci********@gma il.comwrote:
>I've got one thread in my program meant to maintain a timing subsystem
and to do network I/O. It uses the select() system call to either wait
for I/O or "time out" and "handle" some arbitrary "event".
>Is there a way I can cause a thread to wake up, or does anyone have a
suggestion as how to work around this?
The C programming language does not have threads. Any thread
capabilities you have are the result of system or library
extensions beyond C. I suggest that you check the
comp.programmin g.threads newsgroup.
--
"I will speculate that [...] applications [...] could actually see a
performance boost for most users by going dual-core [...] because it
is running the adware and spyware that [...] are otherwise slowing
down the single CPU that user has today" -- Herb Sutter
Jan 2 '08 #2
On Jan 2, 2:24*pm, Richard Cranium <cisrich...@gma il.comwrote:
Hello,

I have an interesting problem:

I've got one thread in my program meant to maintain a timing subsystem
and to do network I/O. *It uses the select() system call to either wait
for I/O or "time out" and "handle" some arbitrary "event".

The timeout value for select() is calculated off of a list of "active
timers" which contains all the necessary information to correctly guess
when select() needs to wake up again if no network I/O occurs.

The problem is, though, that my application is multi-threaded *and
there are times where other threads create and destroy timers. *When
this happens I need to break out of my select() in the I/O & timer
thread, recalulate the timeout value and then go back to sleep.

Is there a way I can cause a thread to wake up, or does anyone have a
suggestion as how to work around this?

Thanks.

-Richard
Richard,

I would recommend you to re-think about your design since you have
threads instantiating timers and destroying them.
It would be best if you could create a module which would keep track
of the ticks and use that. Thus everybody can access this module to
get their job done. Even if the thread dies you are not dependent on
it as the timer module is not killed.

Good luck,
Suresh M. Shenoy
Jan 2 '08 #3

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

Similar topics

0
2573
by: Dima | last post by:
This is my simple code #!/usr/local/bin/perl use threads; use threads::shared; use POSIX::RT::Semaphore; $sem = POSIX::RT::Semaphore->init(0, 0); my $pid = fork;
6
2229
by: Evan David Light | last post by:
After agonizing over this problem for a few days, I've decided to seek help. No, not the variety that involes a jacket that zips up the back but this august body of intrepid individuals. I've discovered the following: - My compile line should resemble: CC -D_PTHREADS -D_POSIX_C_SOURCE=199506L -LANG:std -n32 -mips3 -c <src> -o <obj> - My link line should resemble: CC -LANG:std -n32 -mips3 <objs> -o <executable> -lpthread
6
2487
by: Chaman Singh | last post by:
Hello, I wanted to use Threads on Sun 4 node SMP. In my program I use STL map and I noticed that I don't get any speedup from using threads and I suspect that it has something to do STL map. Can anybody throw some light on this issue ? csv
6
2646
by: Christian Buckl | last post by:
Hi, I try to implement my own thread class based on POSIX threads. I want my class to manage everything (creation of threads, exception handling...). This includes also some functions that need to be called within the threads context (like setting the cancelability state and type). That´s why I am using a function that initializes the thread and then calls the original thread function. The problem is, that I can't manage to implement the...
2
3600
by: raxitsheth | last post by:
Hello All... I am using Posix Thread. class Parent { public: virtual void* func(void *)=0;
11
3017
by: FiLH | last post by:
Hello, I would like to know if posix semaphores are inter processes or just semaphores for threads inside the same process. I have not seen it defined in the posix specification I have found, but I have maybe missed something. Thanks in advance.
2
24284
by: dariophoenix | last post by:
Hi, I am trying to encapsulate Linux sockets and POSIX threads in C++ classes (I work in Knoppix, using KDevelop). Since sockets and threads are new to me, I searched for example code and found the following: #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <netdb.h>
23
5720
by: Boltar | last post by:
Hi I'm writing a threading class using posix threads on unix with each thread being run by an object instance. One thing I'm not sure about is , if I do the following: myclass::~myclass() { : : do stuff
8
4407
by: JackC | last post by:
Hi, I am trying to get posix threads working from within an object, heres some code: int NConnection::TheadControl() { int thread_id; pthread_t new_connection; pthread_create(&new_connection, NULL, PriC, (void *)thread_id);
0
9722
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10643
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10391
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
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
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
6881
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
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3862
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.