Skip to content

C++ library proposing a set of high level classes for threads management

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING
Notifications You must be signed in to change notification settings

Edrusb/libthreadar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ff87570 · Mar 4, 2025
Mar 4, 2025
Aug 21, 2024
Apr 13, 2022
Mar 4, 2025
Aug 21, 2024
Aug 17, 2014
Aug 17, 2014
Aug 21, 2024
Feb 15, 2015
Feb 5, 2025
Mar 4, 2025
Feb 15, 2015

Repository files navigation

What is libthreadar
        libthreadar provides C++ classes for manipulating threads and
        propagating back exception from thread to parent thread when the
        parent calls the join() method

What it is relying on
        libthreadar relies on Posix thread for historical reason, this might
        change in the future to rely on C++11 thread without any impact on
        the API.

Which compiler to use with libthreadar
        To propagate exception of any type libthreadar use C++11 specific
        construction, so it requires such compiler to be compiled and linked
        with.

Why that strange name
        libthreadar has been extracted from code initially part of webdar and
        also now used by dar and libdar, where from its "dar" ending name.
        However this library is not part of webdar, libdar or dar, is
        released separately and can be used independently of them.

Example of use:

        class my_thread: public libthreadar::thread
        {
            public:
                    // class constructor
                my_thread(unsigned int t = 5) { secs = t; };

                    // example method to setup the thread before (re)running it
                void set_time_to_wait(unsigned int t) { secs = t; };

            protected:
                   // this is the code that will run in a separated thread
                virtual void inherited_run() override { sleep(secs); };

           private:
                unsigned int secs;
        };

        my_thread t1(10), t2, t3;

        t2.set_time_to_wait(20);

            // each of the following run() call returns almost immediately:
        t1.run();  // this fires the first thread which sleeps 10 seconds before it ends
        t2.run();  // runs the second thread, it sleeps 20 seconds
        t3.run();  // runs the third thread, which sleeps 5 seconds

        t1.join(); // will wait ~10 seconds for t1 to complete
        t2.join(); // should wait ~10 seconds more for t2 to complete its 20 seconds sleep
        t3.join(); // should return immediately as t3 has already finished its 5 secs sleep

            // a thread object can be run at will several times without having to reset
            // the possibly many parameters it requires to execute:

        t3.set_time_to_wait(100);

        t1.run(); // keeps secs field equal to 10
        t2.run(); // keeps secs field equal to 20
        t3.run(); // modified secs field set to 100

        t1.join(); // join() can propagate exception thrown from within the thread
        t2.join(); //        that lead the thread to end.
        t3.join(); //


Libthreadar advantage summary:
          - your C++ Class inheriting from libthreadar::thread provides a shelter for
            thread dedicated data as private fields.
          - your C++ Class can provide many simple methods to setup the thread parameters
            rather than a long list of parameters provided to a function.
          - Over time it is easy to have a thread class getting new features without breaking
            backward compatibility as it is just a matter of adding new method beside the others
            and setting default values/behavior for those new ones at object construction time.
          - private/protected fields of the class can also hold mutex, semaphores, conditions
            and other constructs to setup communication channels with the running thread, all
            wrapped in public methods for the outside world be able to communicate with the thread
            without having to know the implementation.


Libthreadar Licensing:
        Libthreadar is released under the

                GNU LESSER GENERAL PUBLIC LICENSE.

        For details about this library license see the
        COPYING and COPYING.LESSER files.

Download
        You can download from github or git at sourceforge but you will need
        the auto-tools (automake, autoconf, libtool...) to create the configure
        script. You can instead download ready for use source code (having an
        the configure script built) from sourceforge:

           https://sourceforge.net/projects/libthreadar/files/

        You will find signature beside those packages, see the "Authentication"
        paragraph at http://dar.linux.free.fr/ for signature validation.

Detailed documentation documentation is available online here

          https://libthreadar.sourceforge.net/

        it is built from Doxygen comments found in source code.

About

C++ library proposing a set of high level classes for threads management

Topics

Resources

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING

Stars

Watchers

Forks

Packages

No packages published