Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Communication between threads

by crenz (Priest)
on May 02, 2004 at 19:03 UTC ( #349847=perlquestion: print w/replies, xml ) Need Help??
crenz has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I have problems coming up with a good solution for one thread sending "messages" to another thread. Here's the problem:

A subthread of my program listens on an UDP socket and receives messages. These messages are evaluated and a hash containing parameter values is updated. This hash is marked as shared between threads. The main program displays a wxPerl GUI, including some function plots (drawn using the shared parameter hash). It runs the wxPerl main message loop.

Here's the problem: How can the subthread tell the main thread to redraw the function plots?

The solution I came up with is to define a signal handler in the main thread that implements the GUI updates, then use kill 'SIGUSR1', $$; in the subthread.

The problem with this solution is that the signal is only handled once I activate the application. Ie., when running another application in the foreground, the UDP messages will be received and the signal is sent, but the signal will only be handled after I click on the application's main window. This is unsatisfactory, as I want the function display to be updated immediately.

Is there a way I can work around this problem, or is there a more elegant solution? Thanks for your help!

Edit: I should mention I'm running this on Mac OS X 10.3.3.

Replies are listed 'Best First'.
Re: Communication between threads
by crenz (Priest) on May 02, 2004 at 22:09 UTC
    To answer my own question... I didn't find out why the signals are not caught, but I found out I can use Wx::PostMessage to communicate between the threads. This works just fine for me right now.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://349847]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2017-10-20 00:02 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (258 votes). Check out past polls.