16 typedef std::shared_ptr<std::atomic<bool>>
FlagPtr;
20 std::stringstream string_stream;
24 string_stream >> value;
32 while (!start_flag.load())
34 std::chrono::duration<double> sleep_duration(0.001);
35 std::this_thread::sleep_for(sleep_duration);
38 atomic_fibonacci->nextAndLog();
41 int main(
int argc,
char **argv)
44 int current_number = 1;
68 ROS_INFO(
"Initializing AtomicFibonacci with: ");
79 std::atomic<bool> start_flag;
82 int number_of_threads = 20;
83 std::vector<std::thread> threads;
85 ROS_INFO_STREAM(
"Start spawning " << number_of_threads <<
" threads");
87 for (
int i = 0; i < number_of_threads; ++i)
89 threads.push_back(std::thread(&
callFibonacci, atomic_fibonacci, std::ref(start_flag)));
92 ROS_INFO_STREAM(
"Spawning finished, let's go!");
96 for (
int i = 0; i < threads.size(); ++i)
101 ROS_INFO_STREAM(
"Finished. Goodbye!");
std::shared_ptr< AtomicFibonacci > AtomicFibonacciPtr
int main(int argc, char **argv)
std::shared_ptr< std::atomic< bool > > FlagPtr
void callFibonacci(AtomicFibonacciPtr atomic_fibonacci, std::atomic< bool > &start_flag)
#define ROS_INFO_STREAM(args)