|
GNOME GDK Threads: Cross platform g_threads programming APIThis YoLinux.com GDK threads tutorial is aimed at C/C++ application developers who wish to write parallel processing software with a single multiplatform API.The GDK Threads Reference Manual is a valuable resource for basic use of this API. |
GDK Threads Tutorial Contents:
|
|
Related YoLinux tutorials: °C++ Memory corruption and leaks
Free Information Technology Magazine Subscriptions and Document Downloads
Free Information Technology Software and Development Magazine Subscriptions and Document Downloads
|
This tutorial will cover using the Gnome GDK thread library to build a multi-threaded, parallel processing application for cross platform deployment. GDK threads is a component of the GNOME applications development environment which also includes multi-platform API's for GUIs, graphics, video, window management, XML parsing, internationalization, database access and general application development. The GNOME thread libraries can be used without the GNOME desktop or GUI infrastructure. The API's support the "C" computer language. I usually encapsulate these calls within C++ objects where convenient. Threads allow one to spawn a new concurrent process flow. It is most effective on multiprocessor systems where the process flow can be scheduled by the operating system to run on another processor thus gaining speed through parallel or distributed processing. The GNOME thread libraries are not a feature rich as POSIX threads but do provide the basic infrastructure. For more information on programming threads and concepts, see the YoLinux POSIX Threads Tutorial. For downloading, installation and configuration of the development environment on Ms/Windows with MS/Visual C++ or Cygwin as well as Linux see the YoLinux GTK+ Programming Tutorial
The basic framework of a GDK multi-threaded program requires:
Linux Compile: gcc -o gdk-thread-only gdk-thread-only.c `pkg-config --cflags --libs gtk+-2.0 gthread-2.0` Results:
A mutex is necessary to protect data from corruption or unexpected behavior.
Declare mutex outside of thread scope where it is visible to threaded function:
Notes:
The GDK thread can communicate with the operating system scheduler to yield processing time to other threads. This is preferable to a spinning a loop to delay a thread.
[Potential Pitfall]: When using this cross platform API on Microsoft Windows and compiling with Visual Studio VC++ compiler be sure to use the proper compiler flag to use the appropriate libraries:
|
|
Return to http://YoLinux.com for more Linux links, information and tutorials
Return to YoLinux Tutorial Index Feedback Form Copyright © 2004 by Greg Ippolito |