 	// Host Method
 	int getValue(int thread_id, int val) {
 
+		// wait for possible old task to end
 		while (has_task) {
 		}
 		lock_thread_id = thread_id;

			//do critical section code
			// thread won race condition

			cuPrintf("Thread %d lock_thread_id: %d\n", thread_id,
					d_kernelWrapper->lock_thread_id);

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

			//d_kernelWrapper->lock_thread_id = -1;
			//atomicExch((int *) &d_kernelWrapper, -1);
			//__threadfence_system();
			//__threadfence();

			// exit infinite loop
			break;

		cuPrintf("getValue lock_thread_id: %d result_available: %s\n",
				lock_thread_id, (result_available) ? "true" : "false");

		//lock_thread_id = -1;
		//__threadfence_system();
		__threadfence();
		return result_int;
