Boost logo

Boost Users :

From: lparrab (lparrab_at_[hidden])
Date: 2002-08-28 17:39:57


  
Hi all,
  
I guess my question is not specific to Boost.Thread, but to
threading in general (I'm new at it)... still hope you can help me
out, either directly or by redirecting me to the right place (links
are very much appreciated)
 
I'm starting a multi-threaded program using Boost.Thread library:
it is a "server", in which a thread loops around a "select" to
accept new connections and see when a socket has data to be read, in
which case puts the fds in queue from which other threads are taking
them out to read the data.
The problem I have, is that when a "ReceiverThread" finishes reading
the data from the socket, it puts the fd back in the "all
connections list", but by this time the other ("main")thread already
copied the fds from the list and got into the next "select" loop,
which means the socket from which the "receiver" just finished
reading, will not be "selected" (monitored) untill the next select
loop, which will not be untill a) a new connection comes or b)one of
the other connected sockets gets some data that takes makes the main
thread return from select.
 
reading the select man, I thought I could just use a signal to force
select to return when the "receiver" has put the fd back in the "all
connection list":
 
the threads are now executing something like:
 
main_thread
{
*put all fds from "all sockets" list into a fdset
*make a select on the fdset (block till something interesting
happens)
*take the fds with data out of "all sockets" and put them into
"sockets with data"
*loop
}
 
receiver{
*get a fd from "sockets with data" (if nothing there blocks till the
main_thread sends us a fd through the queue)
*read from fd
*put fd back into "all sockets" (problem: main_thread may be (is!)
already into the select)
*raise(SIGUSR1) (to force select to return and enter the loop
again, but this time with our fd)
}
 
the signal handler for SIGUSR1 does nothing, it just serves to force
select to return, but
the code is not really working as I expected, and I realized that
the problem is that each thread has its own pid, so it seems raise
is actually sending a signal to the wrong thread....
 
as I said, I am new to mulithreading, but I thought all threads run
in a process, which means, they all have the same pid.
->if I first find out the "pid" of the main_thread and change
raise(SIGUSR1) to
kill(pid,SIGUSR1) it works ok.
 
so my question: why does each thread have a own pid?? how can then I
send signals from one thread to another??
I discovered there is a "pthread_kill" function to send signals to
specific threads, the problem is I only have boost::thread objects,
no pthread_t structures.
 
or am I talking nonsense and shouldnt be using signals with
Boost.Thread? if so, how do I solve the select problem??
 
thanx!
 
luis


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net