Iñaki Baz Castillo
7/20/2008 9:50:00 PM
El Domingo, 20 de Julio de 2008, I=C3=B1aki Baz Castillo escribi=C3=B3:
> El Domingo, 20 de Julio de 2008, Joel VanderWerf escribi=C3=B3:
> > You have more control this way,
> > but you have to remember to either set abort_on_exception or to wrap
> > your thread in a handler or to join the thread later. These are three
> > styles, each of which has its place.
>
> Well, thanks for the explanation but I have a doubt.
>
> I run a thread "t2" inside thread "t1" but I don't want "t1" to wait to
> "t2" to finish, this is: I don't need "t1" joins "t2".
>
> I also don't want the main program ends because "t2" produces an exception
> that nobody handles, but I want to see the error. Is not a way to get this
> behaviour?
>
> The only solution I see is t1 joins t2, is it?
Humm, but this is not valid for me, I explain why:
I'm using GServer, so it creates a Thread for each incoming TCP connection =
and=20
runs "serve" method for each one.
In "serve" method I parse the TCP incoming data and process it, but I need=
=20
this connection to remain open and accepting new data even if the received=
=20
data hasn't be processed yet (it's a SIP server). So, in resume I do:
=2D--------------------------------
class GServer
# New Thread for a new IO.
def serve(io)
loop do
data =3D read_IO_incoming_data()
Thread.new {
Logic::process(data)
}
end # loop
end # def serve
end # class GServer
=2D------------------------------
As you see, I need the TCP connection remains open and available ALL the ti=
me,=20
I can wait to process the last received data, so I run a Thread and repeat=
=20
**inmediately** the loop.
Also I need that if an exception occurs in Logic::process(data) it being sh=
own=20
but don't stop the programm (abort_on_exception =3D false). But in this way=
I=20
can't see the error output if it occurs.
How could I get showing the error into the Thread without doing a "join"? (=
I=20
can't do a join).
Thanks a lot for any suggestion.
=2D-=20
I=C3=B1aki Baz Castillo