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

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 3364
In article <2008010214243716807-cisrichard@gmailcom>,
Richard Cranium <ci********@gmail.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.programming.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...@gmail.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
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
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...
6
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...
6
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...
2
by: raxitsheth | last post by:
Hello All... I am using Posix Thread. class Parent { public: virtual void* func(void *)=0;
11
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,...
2
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...
23
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() {...
8
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;...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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.