From a0d7f5a38fc6c698aa54f44d007b06e918c23196 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 21 May 2019 22:36:09 +0200 Subject: [PATCH] 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 #include #include #include #include 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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/deprecated/msg/CMakeLists.txt b/examples/deprecated/msg/CMakeLists.txt index 0e62567023..ac04e1aa3c 100644 --- a/examples/deprecated/msg/CMakeLists.txt +++ b/examples/deprecated/msg/CMakeLists.txt @@ -71,7 +71,14 @@ foreach (x trace-categories trace-route-user-variables trace-link-user-variables ${CMAKE_HOME_DIRECTORY}/examples/deprecated/msg/${x}/${x}.tesh) endforeach() -ADD_TESH_FACTORIES(msg-dht-kademlia-parallel "thread;ucontext;raw;boost" --cfg contexts/nthreads:4 ${CONTEXTS_SYNCHRO} +if(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "i386" AND CMAKE_SIZEOF_VOID_P EQUAL 8) + # Thread-local storage (TLS) is needed for parallel execution, but it doesn't + # play well with Ucontexts on 64bit SunOS (at least on x86_64). + set(parallel-factories "thread;raw;boost") +else() + set(parallel-factories "thread;ucontext;raw;boost") +endif() +ADD_TESH_FACTORIES(msg-dht-kademlia-parallel "${parallel-factories}" --cfg contexts/nthreads:4 ${CONTEXTS_SYNCHRO} --setenv bindir=${CMAKE_BINARY_DIR}/examples/deprecated/msg/dht-kademlia --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/deprecated/msg/dht-kademlia --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms -- 2.20.1