Skip to content

Instantly share code, notes, and snippets.

@KPB3rd
Created April 15, 2022 15:14
Show Gist options
  • Select an option

  • Save KPB3rd/dc08c09a30c245b1b54cbaa8aed3b2c0 to your computer and use it in GitHub Desktop.

Select an option

Save KPB3rd/dc08c09a30c245b1b54cbaa8aed3b2c0 to your computer and use it in GitHub Desktop.
Example of using 2 threads and stopping them if the other finished
std::atomic<bool> is_from_start_solved(false);
std::atomic<bool> is_from_goal_solved(false);
// Example lambda to check if either is high
auto is_path_solved = [&]() -> bool { return is_from_goal_solved.load() || is_from_start_solved.load(); };
auto from_start = [&]() -> void { is_from_start_solved = true; };
auto from_goal = [&]() -> void { is_from_goal_solved = false; };
std::thread t_from_start(from_start);
std::thread t_from_goal(from_goal);
t_from_goal.join();
t_from_start.join();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment