 __global__ void device_method(KernelWrapper *d_kernelWrapper) {
 
 	int thread_id = threadIdx.x + blockIdx.x * blockDim.x;
-
-	int old;
 	int count = 0;
 
 	while (count < 100) {
-		old = atomicCAS((int *) &d_kernelWrapper->lock_thread_id, -1,
+		// (old == -1 ? thread_id : old)
+		int old = atomicCAS((int *) &d_kernelWrapper->lock_thread_id, -1,
 				thread_id);
+
+		cuPrintf("Thread %d old: %d\n", thread_id, old);
 
 		if (old == -1 || old == thread_id) {
 			//do critical section code

	}

	__device__ __host__ int getValue(int val) {

		command = GET_VALUE;
		param1 = val;
		has_task = true;
		//__threadfence_system();

		// wait for socket communication to end
		while (!result_available) {
		}

		reset();
		return result_int;
	}

	__device__ __host__ void sendDone() {


		is_monitoring = false;
		done = false;
		has_task = false;
		//pthread_mutex_init(&mutex_has_task, NULL);

		reset();
