Results 1 to 6 of 6

Thread: Threading Libraries?

  1. #1
    Lesser Knight
    Join Date
    Sep 2006
    Posts
    41

    Default Threading Libraries?

    What threading library does ClanLib use? Native threads, pthreads, Pth, or others?

    I've been looking at threading recently, and I liked what I saw in OpenMP, until I found out that VC Express doesn't support it. Then, I looked to gcc, but you need 4.2 (iirc) for it, and I'm still on 3.4 (of course, I only have cygwin installed for GnuCash, since I've been quite happy with VC, but that's a different story altogether).

    As a slight tangent, does anyone here have threading experience with different libraries, and comparisons between them?

  2. #2
    Lesser Knight
    Join Date
    Sep 2006
    Posts
    41

    Default

    Boy, do I feel sheepish. I don't need another threading library, as I forgot that ClanLib already provides an abstraction for threading!

    Pondering my habit of wishing ClanLib supported certain features, only to realize it already does...

  3. #3
    Lesser Knight
    Join Date
    Sep 2006
    Posts
    41

    Default

    Which brings me to my real question, regarding signals.

    When you have N asynchronous threads running, as N grows the possibility for multiple threads concurrently emitting signals connected to the same slot increases. My question is, does the slot receive the signals serially? Or do I need to make sure my receiving object is reentrant, so that multiple instances of it may receive the signal at the same time?

    As a simple example, say I have several worker threads which, after a lot of computation, send the address for a string to my overseer object (running in its own thread). My overseer object accepts the strings, and prints them to standard output. Will there be multiple instances of my overseer object, one for each signal received, or will it be a single object that will receive all the strings in order, one after the other?

    To quote from the overview on signals and slots: "When a signal is emitted, the slots connected to it are executed immediately, just like a normal function call". This makes it sound like the calling thread is what executes the overseer code to receive signals. Is this correct?

  4. #4
    Squire
    Join Date
    Sep 2006
    Location
    Germany
    Posts
    13

    Default

    AFAIK clanlib uses the natie thrads on win32 and on posix the pthreads, but i'm not sure.
    but i have a question:
    Can someone explain why clanlib doesn't use the Boost.Thread Lib ??
    also, in CLanLib 0.9 the PCRE Liub is used for Regex afaik, but wouldn't it be
    better to use boost.regex ??
    or am I wrong ??
    please tell me....

  5. #5
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    ClanLib uses the native threading APIs available for each platform. In Windows that is CreateThread and so on, on Linux and Mac it uses posix threads (pthreads).

    Regarding the slots and signals, ClanLib classes and functions follow the apartment model, unless otherwise notified. This means that an instance of a class can only be accessed by one thread at a time. It is therefore not safe for two threads to emit the same signal. If you must do it anyway, you have to serialize access to the signal using a mutex (CL_Mutex).

  6. #6
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    Oh and regarding shade31337's question about using boost: ClanLib does not use the boost libraries because ClanLib itself has classes that perform the same tasks that it would otherwise need boost for.

    ClanLib uses PCRE instead of the boost regular expressions because PCRE has a very simple API that makes it easy to wrap it, and it is a library that is well known and tested. This doesn't necessarily make better than the boost regexp lib (in general), but it suited ClanLib better.

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •