Created
January 21, 2014 09:13
-
-
Save hi2p-perim/8536817 to your computer and use it in GitHub Desktop.
A bug. Segmentation fault with g++ 4.7.2, boost 1.54.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <thread> | |
#include <mutex> | |
#include <condition_variable> | |
#include <chrono> | |
#include <boost/signals2.hpp> | |
class A | |
{ | |
public: | |
static A& Instance() | |
{ | |
static A a; | |
return a; | |
} | |
public: | |
boost::signals2::connection Connect(const std::function<void ()>& func) { return signal.connect(func); } | |
void Test() { signal(); } | |
private: | |
boost::signals2::signal<void ()> signal; | |
}; | |
class B | |
{ | |
public: | |
void Run() | |
{ | |
int c = 0; | |
A::Instance().Connect([&](){ c++; }); | |
std::mutex mutex; | |
std::condition_variable cv; | |
std::thread thread( | |
[&]() | |
{ | |
std::unique_lock<std::mutex> lock(mutex); | |
cv.wait(lock); | |
}); | |
std::this_thread::sleep_for(std::chrono::milliseconds(100)); | |
cv.notify_one(); | |
thread.join(); | |
} | |
}; | |
class C | |
{ | |
public: | |
void Run() | |
{ | |
A::Instance().Connect( | |
[&]() | |
{ | |
std::cout << "Hello!" << std::endl; | |
}); | |
A::Instance().Test(); | |
} | |
}; | |
int main() | |
{ | |
B().Run(); | |
C().Run(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment