From: Geoffrey K. <ge...@kn...> - 2003-03-05 21:06:01
|
Tim, thanks for those code examples. I'll keep them for any possible Swing work with threads. However the true motivation for the question had to do with launching a few separate processing tasks in their own threads. For example, processes A1 and A2 are prerequisites for B, and we are just wondering if, in staying with JScheme, we might be able to get A1 and A2 to happen more in parallel. It's nice to know we can. Geoffrey On Wednesday, March 5, 2003, at 03:56 PM, Timothy Hickey wrote: > If you are going to start working with Threads and JScheme you might > want to > be careful when working with Swing GUIs. Swing is not thread safe so > it is a > good idea to execute any GUI manipulations in the AWT event queue > thread. > This is done by using >> (javax.swing.SwingUtilities.invokeAndWait (lambda() ...code to be >> executed...)) >> or >> (javax.swing.SwingUtilities.invokeLater (lambda() ...code to be >> executed...)) > They both add the code to the event Queue as a runnable, this should > only be done > from calls that are forked off of the main thread.... > > I usually also wrap the code in a tryCatch so as to catch any errors > that might occur. > Otherwise the errors cause the thread to halt but are otherwise not > observable: > >> (define(invokeAndWait F) >> (javax.swing.SwingUtilities.invokeAndWait (lambda() >> (tryCatch >> (F) >> (lambda(e) (printdebug 'error {ERROR in invokeAndWait: >> [F], [e]\n}))) >> )) >> ) >> ;; where printdebug is the error printing procedure for your >> application.... >> > > > Have fun, > and be careful out there! > ---Tim--- > > > On Wednesday, March 5, 2003, at 03:46 PM, Geoffrey Knauth wrote: > >> Thanks Tim! Just what the doctor ordered. --Geoffrey >> >> On Wednesday, March 5, 2003, at 03:24 PM, Timothy Hickey wrote: >> >>> (synchronize X F) >>> synchronizes the current thread on object X and blocks until it gets >>> the >>> lock on X, at which time it calls (F X) >>> >>> e.g. >>> (synchronize x .wait) gets a lock on x and then gives up all locks >>> and waits until it is notified >>> (synchronize x .notify) gets a lock on x and then notifies some >>> thread waiting on x >>> >>> I often use the idiom >>> (synchronize g (lambda(g) ....)) >>> or >>> (synchronize g (lambda(_) ...)) >>> >>> ---Tim--- >>> >>> On Wednesday, March 5, 2003, at 01:58 PM, Geoffrey Knauth wrote: >>> >>>> I can use Java threads from JScheme. >>>> >>>> But can I make JScheme variables `synchronized' ? >>>> >>>> Geoffrey >>>> >>>> >>>> >>>> ------------------------------------------------------- >>>> This SF.net email is sponsored by: Etnus, makers of TotalView, The >>>> debugger for complex code. Debugging C/C++ programs can leave you >>>> feeling lost and disoriented. TotalView can help you find your way. >>>> Available on major UNIX and Linux platforms. Try it free. >>>> www.etnus.com >>>> _______________________________________________ >>>> Jscheme-user mailing list >>>> Jsc...@li... >>>> https://lists.sourceforge.net/lists/listinfo/jscheme-user >>>> >>> >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: Etnus, makers of TotalView, The >> debugger for complex code. Debugging C/C++ programs can leave you >> feeling lost and disoriented. TotalView can help you find your way. >> Available on major UNIX and Linux platforms. Try it free. >> www.etnus.com >> _______________________________________________ >> Jscheme-user mailing list >> Jsc...@li... >> https://lists.sourceforge.net/lists/listinfo/jscheme-user >> > |