Boost logo

Boost Users :

Subject: [Boost-users] Boost.Context: SIGSEGV when switch a thread within a catch block
From: Александр Пронченков (alexander_at_[hidden])
Date: 2017-01-01 19:17:14


Hi,

I get SIGSEGV on macOS when I switch an execution_context from a catch
block with one thread and than switch back with another thread.
Segmentation fault happens in libc++abi.dylib`__cxa_end_catch

Does anyone have any ideas, what it could be? Is it legal to switch
thread under an excecution_context while it's within a catch block?

A minimal example is here:

  #include <boost/context/all.hpp>
  #include <future>

  using Context = boost::context::execution_context<void>;

  Context Main(Context context) {
    try {
      throw std::runtime_error("123");
    } catch (const std::exception& ex) {
      context = context();
    }
    return context();
  }

  int main() {
    Context context(&Main);
    context = context();
    std::thread([&] { context = context(); }).join();
    return 0;
  }

I see the problem on macOS with clang++ but can't reproduce on a linux with g++.

$ uname -ap
Darwin air.local 16.3.0 Darwin Kernel Version 16.3.0: Thu Nov 17
20:23:58 PST 2016; root:xnu-3789.31.2~1/RELEASE_X86_64 x86_64 i386

$ clang++ --version
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

--
Thanks,
Alexander Pronchenkov



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net