just::thread Complete C++ Standard Thread Library by Just Software Solutions

Documentation Home

If you're using the Microsoft compiler, then you must add the just::thread include and library directories to your compiler search paths, as described in the readme. By default, the include directory is C:\Program Files\JustSoftwareSolutions\JustThread\include and the library directory is C:\Program Files\JustSoftwareSolutions\JustThread\lib

Once you've done that, using the library is as simple as including the relevant headers and using the functions and classes defined there. Any just::thread headers are included then the appropriate library files are automatically linked in too.

For gcc on Linux, the headers are installed in /usr/include/justthread and the library is installed in /usr/lib. To use the just::thread library, you must specify the correct include path, and the library must be named explicitly when linking. By default it will link against the shared library; if you link against the static library (e.g. with -static command line option) then you must also specify -lrt for timing support. Also, it is important to specify the -pthread option to enable multi-threading support from the compiler:

g++ -pthread -std=c++0x -I/usr/include/justthread \
sample.cpp -o sample -ljustthread

The library will work with or without the -std=c++0x option to enable the gcc C++11 support, but using that option will enable rvalue reference and variadic template support in just::thread, as well as the C++11 support from the compiler. Use (or not) of -std=c++0x must be consistent amongst all translation units, otherwise link failures or unexpected behaviour may occur.

Checking it's all working

To confirm that the just::thread library is correctly installed on your system compile and run the following program:

#include <thread>
#include <mutex>
#include <iostream>

std::mutex io_mutex;

void greeting(const char* message)
{
    std::lock_guard<std::mutex> lk(io_mutex);
    std::cout<<message<<std::endl;
}

int main()
{
    std::thread t(
        greeting,"Hello from another thread");
    greeting("Hello from the main thread");
    t.join();
    return 0;
}

The output should be either

Hello from the main thread
Hello from another thread

or

Hello from another thread
Hello from the main thread

See Also