Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

Wefts++ documentation.


Giancarlo Niccolai


Wefts++ is an high-level abstraction C++ threading library, which has also seamless integration with low level constructs when raw speed is needed.

Wefts++ does not pretends to be a bleeding edge research library; what Wefts++ wants to be is just a set of utilty objects maing multithreading with C++ easier, that will lay gracefully on your C++ application design.

Wefts++ amis to help you develop C++ multithreading application easily and swiftly. Thread programming is an art, and wefts is your paintbrush

NOTICE: Wefts++ uses pthreads. A correct installation of pthread library is essential to use Wefts++.

Obtaining Wefts++

Wefts++ library can be obtained in form of tar gzipped sources, in form of RPM source package or pre-compiled RPM binaries. Installation is easy and it will just install a set of headers and a couple of very small libraries.

It is also possible to get latest developement status of Wefts by downloading the CVS archive:

   cvs -z9 login
   Password: <press enter here>

   cvs -z9 co wefts

Building from source tarball

Under GNU compliant systems, (and also under a lot of unices) a

   make install (** read note)

should be enough. Wefts are installed by default into /usr/local/lib/wefts. That directory will contain an include/ subdirectory, where all the include files are added and lib/ subdirectory, where you can found static (and if you care to build them, dynamic) libraries.

You can chage this default with the option:

   ./configure --prefix=/my/favourite/

You could i.e. install wefts libs under /usr/libs and include files under /usr/include by just configuring with --prefix=/usr (if you find this library really useful :-). You could also set specific destination for wefts headers and libraries. In example:

   ./configure --prefix=/usr --libdir=lib/wefts --includedir=include/wefts

will move libraries and includes in your system standard directory, but under wefts subdirectory (/usr/include/wefts for headers and /usr/lib/wefts for libraries).

if you install wefts in a standard directory, using i.e. --prefix=/usr, you will be able to use include files, static and expecially dynamic libraries without any extra compilation/link flag.
A script mamed "wefts-conf" will be installed in your /usr/local/bin dir; it is a small script that you can later on use in your makefiles to automatically add the compilation and library flags needed to link against wefts. If you don't like this, you can call ./configure --bindir=... to set a different relative or absolute path. A relative path will be added below --prefix directory.

Installing from CVS

Provided you have autoconf 2.5+, automake 1.6+ and a recent libtool, this command sequence should be enough:

   libtoolize --automake
   automake -a

And then you can continue with configure, make and make install. "automake -a" is important, as it will create the standard GNU support utilities to do a clean configure/make process.

Other configure options

To enable debuging symbols add --enable-debug, and to make also tests (linked against static library) do --enable-tests.

Dynamic libraries can be built by passing --enabled-shared to configure. Anyhow, wefts is a very small library, and most of it is held in inline C++ methods; for this reason, using only the static library version makes perfectly sense.

Rpm installation

Wefts can also be installed from RPM on Mandrake and Red Hat LINUX systems, and on those systems that support RPM. The library installation is done under /usr/lib, include files are installed in /usr/include/wefts, while wefts-conf script is placed in /usr/bin dir.

To install the package, you need libpthread.a to be in /usr/lib.

The command rpm -ivh wefts-...rpm will be enough.


Once you have configured and installed the package, if you don't like the libraries anymore ;,( a make uninstall will remove installed files.

If you have installed using rpm, the command rpm -e wefts wil remove the package.

Getting Started

This manual is meant to be just an api reference (and a configuration guide) for Wefts; cute tutorials, FAQ, and other things like that can be found at wefts home site

However, we present here a minimal survival guide on how to compile and use wefts.

To test if your installation is correct, check out this test:

// Weftstest.cpp - an introductory test

#include <wefts.h>
#include <iostream>

using namespace Wefts;
using namespace std;

class MyThread: public Thread
   void *run()
      cout << "Begin of thread" << sequence() -1 << endl;
      Sleep( 2.5 );
      cout << "End of thread" << sequence() -1 << endl;
      return 0;

int main( int argc, char *argv[] )
   for ( int i = 0;i < 4; i ++ ) {
      MyThread *th = new MyThread();

   //we'll wait for our children to terminate:
   runningThreads.until( 1 ); // until there is only 1 thread left (myself).

   cout << "Main thread done!" << endl;
   return 0;

This simple program can be compiled using the command

   $ gcc -o weftstest $(wefts-conf -c) weftstest.cpp $(wefts-conf -s -l)

This command will call wefts-conf two times; the first one will provide some basic C++ flag, including the "include" dir that is needed to do include <wefts.h>. The scond one will tell where to get the wefts library that has to be linked.

If you don't have installed dynamic libraries, (that is, if you don't have enabled them with --enable-shared in configure script), that "-s" option in wefts-conf isn't necessary. In fact, that option just tells to get exactly the static library. Wefts is a very small library (under 50 Kb), so it is possible that the final developre does not want to link against dynamic libraries, with the need to install them everywhere the program has to run.

Installing and using dynamic libraries

Dynamic libraries are a little more tricker. By default they are installed in /usr/local/lib/wefts/lib; this means that you need to do something to tell the program loader where the libraries are, to use them. You can do three ways:

In RPM installation, the default library directory is /usr/lib, so the "error while loading shared libraries" is bypassed; anyway, it is still worth to link Wefts++ statically so the resulting program can be moved around without having to install the library.

Enough! I want to start thread programming!

Ok, Ok, I feel that way too :-)

So, what can you do now? The main class here is Wefts::Thread; have a look at it. Then you will need some way to synchronize threads: Wefts::Mutex and Wefts::RMutex are what you are searching for.

If you are accustomed with posix condition and signals, the Wefts::FastCondition and Wefts::RCondition classes are implementing that model. If you are not accustomed with them, or if you have enough of condition signaling, well, have a look at them anyway; you could find new way to use them in this C++ object oriented environment. They are absolutely excellent to send safely a data that is produced in a thread to another thread that is waiting for that.

A little step further is required for Wefts::RWMutex and Wefts::RRWMutex.

Then, when you have a certain maestry in this classes, have a look at the Wefts::Barrier, the Wefts::Subscription and finally the Wefts::MoaningThread (TM). -- this (TM) is a joke.

But I would like to see some sample...

Almost all features are demonstrated by little programs in the tests/ subdirectory of the source distribution (both SRPM and tarball has it, or you can browse our CVS). They will be compiled (from tarball) if you set ./configure --enable-tests.

They are somehow self explanatory, and are worth a look anyway.

Ok, all this is nice, but I need some tutorial

Sorry. Not here. Try to see to see if me (or another contributor) had the time to add some. Or scan the net to see how other programmers have solved the problem you have. And if you are lost, send me a mail. (My address is about everywhere in the distribution...)

Enjoy threading!

Giancarlo Niccolai

Generated on Tue Aug 5 18:09:00 2003 for Wefts by doxygen1.2.18