void *run(int tid, void (*lock_function)(type *), void (*unlock_function)(type *), int *lock_accesses, int lock_accesses_size) { if (pin && stick_this_thread_to_core(tid % num_cores) != 0) printf("Could not pin thread\n"); int ops = 0; // use local variable, otherwise we're potentially in the same cache line as other threads int i = 0; while (!stop_run) { int access = lock_accesses[i]; type* mutex_ptr = &mutexes[access].value; #if DEBUG == 1 printf("[T#%d] Locking %d (%p)\n", tid, access, mutex_ptr); #endif lock_function(mutex_ptr); nop_wait(sleep_time); #if DEBUG == 1 printf("[T#%d] Unlocking %d (%p)\n", tid, access, mutex_ptr); #endif unlock_function(mutex_ptr); ops++; i++; i = i % lock_accesses_size; } operations_count[tid] = ops; }
void Fl::unlock() { unlock_function(); }