From: Plum, J. <jp...@ba...> - 2006-02-11 19:32:55
|
Yes, it is correct that it allows the main thread to communicate with = the child threads via the Window Message Queue (though I am workin on a = way to make it last beyond the Window's lifespan). And techinically... no, sending data that way wont work quite yet... but that is the general idea in the end. I plan on moving things to a ThreadsSafe::SendMessage() form in order to = allow lifespan of the children beyond that of the window message queue, = as well as provide and *easy* way of transfering the data to that queue. the format for sending message then would be more along ths lines of: ThreadsSafe::SendMessage(MESSAGE, WPARAM, LPARAM[, DATA]); the reference is a scalar/list/hash/storable object, that will be frozen = by storable and then put on the destination threads's queue, where it = will be sent over to the callback for that threads, in its original form = via thaw. But I think you get the general idea. :) Jason P. -----Original Message----- From: Jeremy White [mailto:jez...@ho...] Sent: Sat 2/11/2006 5:19 AM To: Plum, Jason; per...@li... Subject: RE: [perl-win32-gui-users] Thread Safe Message Passing =20 >Since I was looking for something slightly different than Rob had >provided, I managed to make use of his example (TY Rob) and turn it >around into something more 'famliliar'. Thanks for posting the code - the more feedback and comments, the better = the=20 final solution will be:) >The attached 2 files: >ThreadSafe.pm >Threadsafe_1.pl > >The module is built around the idea that there *had* to be a way to get >messages from the windows thread (main aka tid =3D=3D 0 ) to the child >threads. Would this be the correct usage of your module: #Add this after the window has been created $win->AddButton( -name =3D> 'test', -text =3D> 'test', -pos =3D> [114, 10], -height =3D> 20, -onClick =3D> \&butclick, ); sub butclick { for (1..5) { $win->SendMessage(WM_PIPE1,M_DATA,['some data',$_]); $win->SendMessage(WM_PIPE2,M_DATA,['some data',$_]); } } When the button is clicked, 5 messages are sent to both spawned threads. = Is=20 that correct? Would be correct to say that the essence of your package = is=20 that it allows the main thread to communicate with child threads via the = windows message queue? Cheers, jez. |