 	// lock_thread_id was already set
 	__device__ int getValue(int val) {
 
+		int timeout = 0;
+		// wait for possible old task to end
 		while (has_task) {
+			if (++timeout > 10000) {
+				cuPrintf(
+						"getValue TIMEOUT wait forold task to end! lock_thread_id: %d\n",
+						lock_thread_id);
+				break;
+			}
 		}
 		cuPrintf("getValue lock_thread_id: %d val: %d\n", lock_thread_id, val);
 

	// Host Method
	int getValue(int thread_id, int val) {

		while (has_task) {
		}
		lock_thread_id = thread_id;

		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;
