> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of zentara
> Sent: Wednesday, June 20, 2007 8:13 AM
> To: beginners@perl.org
> Subject: Re: Inter-thread communications
> 
> On Tue, 19 Jun 2007 15:44:18 -0400, [EMAIL PROTECTED] ("Bob McConnell")
> wrote:
> 
> 
> >I have been trying to implement this in ActivePerl 5.8.8.820 
> on W2K, so
> >I am working in the thread based fork() implementation. IPC does not
> >seem to exist in that implementation.
> 
> For forked processes, you need pipes, sockets, or shared mem for
> IPC.  
> 
> You probably are better off sticking with threads on Win32, since
> it only uses threads underneath it all.
> 
> >I had pretty much figured out that alarm doesn't work in Win32. I had
> Alarm dosn't work on linux with threads either ( or not as you would
> expect.... the main thread intercepts all alarms).
> 
> >tried to use it to interrupt read() on a serial port, and that wasn't
> >working. Neither did SIGINT or SIGTERM. The only way to get out of it
> >was Ctrl->Break, which shuts down the whole process.
> >
> >Unless the Glib timer can interrupt a serial port read() 
> call, I don't
> >see any way to timeout a serial port input function on Win32.
> >Unfortunately, that means I will probably need to steal one 
> of the FC5
> >boxes from the next room in order to get it to work.
> 
> Yeah, Glib should be able to do it with some "flagging magic". I don't
> have an example offhand, but if you look at that perlmonks url, about
> rolling your own event loop, you can see how it MIGHT be done :-)
> 
> .....pseudo-code follows......
> 
> ###  filehandle watch
> open (FH, "+> test.log") or warn "$!\n";     # simulate your socket
> 
> Glib::IO->add_watch (fileno 'FH', ['in'], \&watch_callback, 'FH', 1 );
> 
> $main_loop->run;
> ####################################################################
> sub watch_callback {
>     my ($fd, $condition, $fh) = @_;
> 
>     if($flag){return 1}  # test for timer flag
> 
>     my @lines = <FH>;
>     print @lines;
> 
>    # here you might regex the lines for Ack or Nack, and if found,
>    #launch a timer to set a flag after 3 seconds ( act as alarm) 
>    my $timer  = Glib::Timeout->add (3000, \&timer_callback, 
> undef, 1 );
> 
> 
>     #always return TRUE to continue the callback
>     return 1;
> }       
> 
> 
> 
> Like I said it was just pseudo code, and I have to admit, it would
> probably take a few hours of realtime testing scripts, to see how
> the serial port socket actually behaves..... the devil is 
> always in the
> details.
> 
> Switching to a linux box would make things work better for sure, but
> first I recommend checking out POE. It is an advanced 
> event-loop system
> that has alot of the bugs worked out.
> There is a POE cookbook of examples online, and you may find
> something close to your needs.
> POE does offer alarms and signals.
> 
> http://poe.perl.org/?POE_Cookbook
> 
> 
> zentara

Thank your for those ideas. I don't know how far I will get with POE
since I don't do objects. At this point I have to think about switching
to C for this project. I know I could throw it together in a couple of
days using GCC in Cygwin, which is already installed. I have spent more
time than that trying to do it in Perl.

Bob McConnell

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to