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/advanced.html | 89 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 documentation/advanced.html (limited to 'documentation/advanced.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(). + + + + -- cgit v1.2.3