Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <thread>
- #include <chrono>
- #define HIS 0
- #define HERS 1
- uint8_t resolved_disputes = 0;
- uint8_t turn = 0;
- void husband() {
- uint8_t disputes;
- for (int i = 0; i < 30;) {
- if (turn == HIS) {
- disputes = resolved_disputes;
- disputes = disputes + 1;
- std::this_thread::sleep_for(std::chrono::nanoseconds(1));
- resolved_disputes = disputes;
- i++;
- turn = HERS;
- }
- }
- turn = HERS;
- }
- void wife() {
- uint8_t disputes;
- for (int i = 0; i < 30;) {
- if (turn == HERS) {
- disputes = resolved_disputes;
- disputes = disputes + 1;
- std::this_thread::sleep_for(std::chrono::nanoseconds(1));
- resolved_disputes = disputes;
- i++;
- turn = HIS;
- }
- }
- turn = HIS;
- }
- int main() {
- resolved_disputes = 0;
- std::thread t1(husband);
- std::thread t2(wife);
- t1.join();
- t2.join();
- std::cout << "resolved disputes: " << (int)resolved_disputes << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement