Changeset cf444b6
- Timestamp:
- Jul 12, 2021, 1:43:15 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 6ff08d8
- Parents:
- eba9d27
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/unified_locking/thread_test.cfa
reba9d27 rcf444b6 8 8 static unsigned int threadCount = 2; 9 9 static unsigned int lockCount = 1; 10 static unsigned int num_times = 10000; 10 static unsigned int total_times = 320000; 11 static unsigned int num_times; 11 12 static const int workBufferSize = 16; 12 13 static unsigned int work_unlocked = 10000; … … 25 26 thread worker { 26 27 linear_backoff_then_block_lock * locks; 28 bool improved; 27 29 }; 28 30 29 void ?{}( worker & w, linear_backoff_then_block_lock * locks ) {31 void ?{}( worker & w, linear_backoff_then_block_lock * locks, bool improved ) { 30 32 w.locks = locks; 33 w.improved = improved; 31 34 } 32 35 33 linear_backoff_then_block_lock norm_lock;34 36 35 37 void main( worker & this ) with(this) { … … 37 39 for (int i = 0; i < workBufferSize; i += 1) buffer[i] = rand() % 1024; 38 40 unsigned int lck = rand() % lockCount; 39 linear_backoff_then_block_lock * curr_lock = locks;//[lck];41 linear_backoff_then_block_lock * curr_lock = &locks[lck]; 40 42 for (unsigned int i = 0; i < num_times; i++) { 41 43 dowork(buffer, work_unlocked); 42 lock(curr_lock); 43 //printf("lock: %d %p ENTER\n", i, &curr_lock); 44 //lock(norm_lock); 44 if (improved) lock_improved(*curr_lock); 45 else lock(*curr_lock); 45 46 dowork(buffer, work_locked); 46 //printf("lock: %d %p LEAVE\n", i, &curr_lock); 47 unlock(curr_lock); 48 //unlock(norm_lock); 47 unlock(*curr_lock); 49 48 lck = rand() % lockCount; 50 //curr_lock =locks[lck];49 curr_lock = &locks[lck]; 51 50 } 52 51 } 53 52 53 54 54 int main(int argc, char* argv[]) { 55 55 switch (argc) { 56 case 7: 57 work_unlocked = atoi(argv[5]); 58 case 6: 59 work_locked = atoi(argv[5]); 56 60 case 5: 57 61 num_times = atoi(argv[4]); … … 68 72 } 69 73 processor p[threadCount]; 70 linear_backoff_then_block_lock locks;//[lockCount]; 71 printf("lock allocation address: %p \n", &locks); 74 linear_backoff_then_block_lock locks[lockCount]; 72 75 worker * worker_arr[taskCount]; 76 num_times = total_times / taskCount; 73 77 74 printf("Start Test: martin lock simple\n");78 //printf("Start Test: martin lock simple\n"); 75 79 clock_t begin = clock(); 76 80 for (unsigned int i = 0; i < taskCount; i++) { 77 worker_arr[i] = new( &locks);81 worker_arr[i] = new( locks, false ); 78 82 } 79 83 for (unsigned int i = 0; i < taskCount; i++) { 80 free( worker_arr[i] );84 delete( worker_arr[i] ); 81 85 } 82 86 clock_t end = clock(); 83 87 double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; 84 printf("Done Test, time: %f\n", time_spent); 88 printf("norm: %f\n", time_spent); 89 90 //printf("Start Test: martin lock improved\n"); 91 begin = clock(); 92 for (unsigned int i = 0; i < taskCount; i++) { 93 worker_arr[i] = new( locks, true ); 94 } 95 for (unsigned int i = 0; i < taskCount; i++) { 96 delete( worker_arr[i] ); 97 } 98 end = clock(); 99 time_spent = (double)(end - begin) / CLOCKS_PER_SEC; 100 printf("improved: %f\n", time_spent); 85 101 }
Note: See TracChangeset
for help on using the changeset viewer.