From 11a15d83a2be539c0e660c20ab92d8d4d2736f99 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Tue, 6 Mar 2007 17:15:03 +0000 Subject: This is a suggested change. It is complete except for documentation. I did not like the awake_cb system at all. These changes implement Fl::awake(Fl_Awake_Handler, void*) which is called from a thread and tells the main loop to call the specified handler (rather a callback I guess) as soon as possible from within the main thread. It is implemented as Fifo (currently 1024 entry ring buffer), so handlers are called in the order that they are generated in. "test/threads" was modified to change the label color as soon as a thread reaches 10000 - pretty boring, but it show the wonderful simplicity of this approach: you can write libraries that don't need to add to the main loop or register a handler at all... . I will do some more stress testing tonight. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5729 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- test/threads.cxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/threads.cxx b/test/threads.cxx index fdd2f553c..c7107c235 100644 --- a/test/threads.cxx +++ b/test/threads.cxx @@ -32,6 +32,7 @@ # include # include # include +# include # include "threads.h" # include # include @@ -42,12 +43,20 @@ Fl_Browser *browser1, *browser2; Fl_Value_Output *value1, *value2; int start2 = 3; +void magic_number_cb(void *p) +{ + Fl_Value_Output *w = (Fl_Value_Output*)p; + w->labelcolor(FL_RED); + w->redraw_label(); +} + void* prime_func(void* p) { Fl_Browser* browser = (Fl_Browser*) p; Fl_Value_Output *value; int n; int step; + char proud = 0; if (browser == browser2) { n = start2; @@ -86,6 +95,10 @@ void* prime_func(void* p) // message we pass here isn't used for anything, so we could also // just pass NULL. Fl::awake(p); + if (n>10000 && !proud) { + proud = 1; + Fl::awake(magic_number_cb, value); + } } else { // This should not be necessary since "n" and "step" are local variables, // however it appears that at least MacOS X has some threading issues -- cgit v1.2.3