ADT
ast-experimental
|
Last change
on this file since afffd6c was 357ab79, checked in by caparsons <caparson@…>, 3 years ago |
|
moved unified locking tests to be under concurrent directory since they probably should have been there this whole time
|
-
Property mode
set to
100644
|
|
File size:
1019 bytes
|
| Line | |
|---|
| 1 | #include "locks.hfa"
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 | fast_block_lock f;
|
|---|
| 5 | fast_cond_var( fast_block_lock ) f_c_f;
|
|---|
| 6 | condition_variable( fast_block_lock ) c_f;
|
|---|
| 7 |
|
|---|
| 8 | unsigned int num_times = 10000;
|
|---|
| 9 |
|
|---|
| 10 | thread T_F_C_F_WS1 {};
|
|---|
| 11 |
|
|---|
| 12 | void main( T_F_C_F_WS1 & this ) {
|
|---|
| 13 | for (unsigned int i = 0; i < num_times; i++) {
|
|---|
| 14 | lock(f);
|
|---|
| 15 | if(empty(f_c_f) && i != num_times - 1) {
|
|---|
| 16 | wait(f_c_f,f);
|
|---|
| 17 | }else{
|
|---|
| 18 | notify_one(f_c_f);
|
|---|
| 19 | unlock(f);
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | thread T_C_F_WS1 {};
|
|---|
| 25 |
|
|---|
| 26 | void main( T_C_F_WS1 & this ) {
|
|---|
| 27 | for (unsigned int i = 0; i < num_times; i++) {
|
|---|
| 28 | lock(f);
|
|---|
| 29 | if(empty(c_f) && i != num_times - 1) {
|
|---|
| 30 | wait(c_f,f);
|
|---|
| 31 | }else{
|
|---|
| 32 | notify_one(c_f);
|
|---|
| 33 | unlock(f);
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | int main(int argc, char* argv[]) {
|
|---|
| 39 | int variation = 0;
|
|---|
| 40 | switch (argc) {
|
|---|
| 41 | case 3:
|
|---|
| 42 | num_times = atoi(argv[2]);
|
|---|
| 43 | case 2:
|
|---|
| 44 | variation = atoi(argv[1]);
|
|---|
| 45 | case 1:
|
|---|
| 46 | break;
|
|---|
| 47 | default:
|
|---|
| 48 | break;
|
|---|
| 49 | }
|
|---|
| 50 | processor p[1];
|
|---|
| 51 |
|
|---|
| 52 | if (variation == 0) {
|
|---|
| 53 | T_F_C_F_WS1 t[2];
|
|---|
| 54 | }else if (variation == 1) {
|
|---|
| 55 | T_C_F_WS1 t[2];
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.