Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Posix Threads and select()

Reply
Thread Tools

Posix Threads and select()

 
 
Richard Cranium
Guest
Posts: n/a
 
      01-02-2008
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

 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      01-02-2008
In article <2008010214243716807-cisrichard@gmailcom>,
Richard Cranium <(E-Mail Removed)> wrote:
>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
 
Reply With Quote
 
 
 
 
suresh shenoy
Guest
Posts: n/a
 
      01-02-2008
On Jan 2, 2:24*pm, Richard Cranium <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic Question on POSIX Threads JackC C++ 14 10-16-2007 08:24 PM
Creating POSIX threads with a class function Christian Buckl C++ 6 10-08-2004 02:33 PM
STL map and Posix Threads Chaman Singh C++ 3 04-09-2004 07:02 PM
POSIX Threads causing memory leak Heiko Neuhaus C++ 3 12-21-2003 07:16 AM
Problem using IRIX 6.5 CC (MIPSPro C++) STL I/O w/ POSIX threads Evan David Light C++ 6 12-01-2003 06:29 PM



Advertisments