Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Communication between threads by crenz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-24 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found