From 8e7e4167835186b2aab81c4e87153c574ff83466 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 18 Jan 2007 22:48:19 +0000 Subject: Added chapter 10 with documentation about multithreading git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5621 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- documentation/Fl.html | 13 +++++++ documentation/Makefile | 1 + documentation/advanced.html | 89 +++++++++++++++++++++++++++++++++++++++++++++ documentation/index.html | 3 ++ 4 files changed, 106 insertions(+) create mode 100644 documentation/advanced.html (limited to 'documentation') diff --git a/documentation/Fl.html b/documentation/Fl.html index 8cd78507a..281ef7b8a 100644 --- a/documentation/Fl.html +++ b/documentation/Fl.html @@ -395,6 +395,13 @@ main thread, causing any pending wait() call to terminate so that the main thread can retrieve the message and any pending redraws can be processed. +

Multiple calls to awake() will overwrite the same +message pointer. +thread_message() only returns +the last message stored by the last awake() call. + +

See also: multithreading +

void background2(uchar, uchar, uchar);

Changes the alternative background color. This color is used as a @@ -961,6 +968,8 @@ wait until all child threads have called unlock() before processing additional data. +

See also: multithreading +

Fl_Window* modal();

Returns the top-most modal() window currently shown. @@ -1236,6 +1245,8 @@ Fl_Widget::test_shortcut(). that was sent from a child by the awake() method. +

See also: multithreading +

void unlock();

The unlock() method releases the lock that was set @@ -1243,6 +1254,8 @@ using the lock() method. Child threads should call this method as soon as they are finished accessing FLTK. +

See also: multithreading +

double version();

Returns the compiled-in value of the FL_VERSION constant. This diff --git a/documentation/Makefile b/documentation/Makefile index f57e3aef7..8dcf9476b 100644 --- a/documentation/Makefile +++ b/documentation/Makefile @@ -54,6 +54,7 @@ HTMLFILES = \ subclassing.html \ opengl.html \ fluid.html \ + advanced.hml \ widgets.html \ Fl.html \ Fl_Adjuster.html \ diff --git a/documentation/advanced.html b/documentation/advanced.html new file mode 100644 index 000000000..52c3009b6 --- /dev/null +++ b/documentation/advanced.html @@ -0,0 +1,89 @@ + + + 10 - Advanced FLTK + + + +

10 - Advanced FLTK

+ +

This chapter explains advanced programming and design topics +that will help you to get the most out of FLTK.

+ +

10.1 Multithreading

+ +

FLTK supports multithreaded application using a locking mechanism +based on "pthreads". We do not provide a threading interface +as part of the library. However a simple example how threads can +be implemented for all supported platforms can be found in +test/threads.h and test/threads.cxx. + +

To use the locking mechanism, the command line version of FLTK +must be compiled with --enable-threads set during the +configure process. IDE-based versions of FLTK are +automatically compiled with locking enabled if possible. + +

In main(), before calling Fl::run(), call +Fl::lock(). This will startup the runtime multithreading +support for your program. All callbacks and derived functions +like handle() and draw() will now be properly +locked. + +

+  main() {
+    Fl::lock();
+    /* run thread */
+    while(Fl::wait() > 0) {
+      if(Fl::thread_message()) {
+        /* process your data */
+      }
+    }
+  }
+
+
+ +

You can now start as many threads as you like. From within +a thread (other than the main thread) FLTK calls must be wrapped +in the following code: + +

+  Fl::lock();      // avoid conflicting calls
+  ...              // your code here
+  Fl::unlock();    // allow other threads to access FLTK again
+  Fl::awake(msg);  // tells FLTK that another thread has made changes
+
+
+ +

FLTK supports multiple platforms, some of them which do not +allow any other but the main thread to handle system events and +open or close windows. The safe thing to do is to adhere to the +following rulesi for threads on all operating systems. + +

+ +

See also: +void lock(), +void unlock(), +void awake(void *message), +void *thread_message(). + + + + diff --git a/documentation/index.html b/documentation/index.html index 001b9e627..5187f0789 100644 --- a/documentation/index.html +++ b/documentation/index.html @@ -73,6 +73,9 @@

  • Selecting Moving Widgets
  • Image Labels
  • + 10 - Advanced FLTK +
    +
    A - Class Reference

    -- cgit v1.2.3