Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
108 changed files
with
9,618 additions
and
771 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <thread> | ||
#include <mutex> | ||
|
||
using namespace std; | ||
|
||
const int MAX_ITER = 500000; | ||
mutex pi, po; | ||
|
||
void ping() { | ||
for (int i = 0; i < MAX_ITER; ++i) { | ||
pi.lock(); | ||
printf("ping\n"); | ||
po.unlock(); | ||
} | ||
} | ||
|
||
void pong() { | ||
for (int i = 0; i < MAX_ITER; ++i) { | ||
po.lock(); | ||
printf("pong\n"); | ||
pi.unlock(); | ||
} | ||
} | ||
|
||
int main() { | ||
thread t1(ping); | ||
thread t2(pong); | ||
t1.join(); | ||
t2.join(); | ||
return 0; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.