 		result_available = false;
 		result_int = 0;
 
+		lock_thread_id = -1;
+
 		pthread_mutex_init(&mutex_process_command, NULL);
 
 		reset();
 	}
 
 	void reset() volatile {
-		lock_thread_id = -1;
 		command = UNDEFINED;
 		has_task = false;
 		printf("KernelWrapper reset lock_thread_id: %d, has_task: %s\n",

		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

			int val = d_kernelWrapper->getValue(thread_id);
			cuPrintf("Thread %d getValue: %d\n", thread_id, val);

			d_kernelWrapper->lock_thread_id = -1;
			__threadfence();
			// exit infinite loop
			break;

