Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Disable parallel ucontexts on 64bit SunOS.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 21 May 2019 20:36:09 +0000 (22:36 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 21 May 2019 20:44:14 +0000 (22:44 +0200)
commita0d7f5a38fc6c698aa54f44d007b06e918c23196
tree3008eabc6c3a3d7507dc8320c8eecc4d74d772f1
parent955310e4fe48139407cabfd6cae815a287932291
Disable parallel ucontexts on 64bit SunOS.

Ucontexts and TLS don't play well together on this platform.

For the record, here is a sample test code. The output should be the same before and after
swapcontext (recall that option "-m64" may be mandatory to compile in 64bit mode).

--------------------
#include <iostream>
#include <stdexcept>
#include <system_error>
#include <thread>
#include <ucontext.h>

thread_local int x = 1;

static char stack[66536];
static ucontext_t ctx;
static ucontext_t octx;

static void wrap()
{
    std::cerr << "o. After swapcontext...: x = " << x << " (" << std::this_thread::get_id() << ")\n";
}

static void thread_fun()
{
    x = 2;
    std::this_thread::sleep_for(std::chrono::milliseconds(100));

    ctx.uc_stack.ss_sp = stack;
    ctx.uc_stack.ss_size = sizeof(stack);
    ctx.uc_link = &octx;
    makecontext(&ctx, &wrap, 2, (int)0xdeadbeef);
    std::cerr << "o. Before swapcontext..: x = " << x << " (" << std::this_thread::get_id() << ")\n";
    swapcontext(&octx, &ctx);
    std::cerr << "o. Finish of thread....: x = " << x << " (" << std::this_thread::get_id() << ")\n";
}

int main()
{
    std::cerr << "x. Main (before thread): x = " << x << " (" << std::this_thread::get_id() << ")\n";
    std::thread thr(thread_fun);
    getcontext(&ctx);
    thr.join();
    std::cerr << "x. Main (after join)...: x = " << x << " (" << std::this_thread::get_id() << ")\n";
}
examples/deprecated/msg/CMakeLists.txt