Created
April 15, 2022 15:14
-
-
Save KPB3rd/dc08c09a30c245b1b54cbaa8aed3b2c0 to your computer and use it in GitHub Desktop.
Example of using 2 threads and stopping them if the other finished
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
| 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