mirror of
https://github.com/boostorg/fiber.git
synced 2026-02-02 08:52:07 +00:00
variadric tempalte args
This commit is contained in:
49
examples/cpp03/interrupt.cpp
Normal file
49
examples/cpp03/interrupt.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <boost/fiber/all.hpp>
|
||||
|
||||
struct condition_test_data
|
||||
{
|
||||
condition_test_data() : notified(0), awoken(0) { }
|
||||
|
||||
boost::fibers::mutex mutex;
|
||||
boost::fibers::condition condition;
|
||||
int notified;
|
||||
int awoken;
|
||||
};
|
||||
|
||||
void condition_test_fiber(condition_test_data* data)
|
||||
{
|
||||
boost::unique_lock<boost::fibers::mutex> lock(data->mutex);
|
||||
while (!(data->notified > 0))
|
||||
data->condition.wait(lock);
|
||||
data->awoken++;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
condition_test_data data;
|
||||
boost::fibers::fiber f(boost::bind(&condition_test_fiber, &data));
|
||||
|
||||
f.interrupt();
|
||||
try
|
||||
{
|
||||
f.join();
|
||||
|
||||
std::cout << "done." << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch ( boost::fibers::fiber_interrupted const&)
|
||||
{ std::cerr << "interrupted" << std::endl; }
|
||||
catch ( std::exception const& e)
|
||||
{ std::cerr << "exception: " << e.what() << std::endl; }
|
||||
catch (...)
|
||||
{ std::cerr << "unhandled exception" << std::endl; }
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
Reference in New Issue
Block a user