 	h_kernelWrapper->init();
 	h_kernelWrapper->startMonitor();
 
+	// wait for kernelWrapper monitoring
+	while (!h_kernelWrapper->is_monitoring) {
+	}
+	printf("KernelWrapper is_monitoring: %s\n",
+			(h_kernelWrapper->is_monitoring) ? "true" : "false");
+
 	// test call host_kernelWrapper
 	//h_kernelWrapper->active_thread_id = 0;
 	//int value = h_kernelWrapper->getValue(0);

	~KernelWrapper() {
	}

	void startMonitor() {
		pthread_create(&t_monitor, NULL, &KernelWrapper::thread, this);
	}

	static void *thread(void *context) {
		volatile KernelWrapper *_this = ((KernelWrapper *) context);

		while (!_this->done) {
			//printf(
			//		"MonitorThread has_task: %s, active_thread_id: %d, command: %d\n",
			//		(_this->has_task) ? "true" : "false",
			//		_this->active_thread_id, _this->command);

			if ((!_this->has_task) && (_this->active_thread_id >= 0)
					&& (_this->command != UNDEFINED)) {
				_this->has_task = true;
				_this->sendCommand();
			}
		}
		return NULL;
	}

	void sendCommand() volatile {

		printf("MonitorThread sendCommand!\n");

		switch (command) {


		}
		case DONE: {
			socket_client.sendCMD(DONE);
			result_available = true;
			break;
		}

		}
	}

	__device__ __host__ void reset() {
		lock_thread_id = -1;
		command = UNDEFINED;
		has_task = false;
		task_accepted = false;
		result_available = false;
	}

	__device__ __host__ int getValue(int val) {

		// wait for wrapper thread to end
		while (has_task) {
		}

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

		// wait for wrapper thread to accept
		while (!task_accepted) {
		}

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

		reset();
		return result_int;
	}

	__device__ __host__ void sendDone() {
		command = DONE;
		has_task = true;

		// wait for wrapper thread to accept
		while (!task_accepted) {
		}

		printf(
				"KernelWrapper::sendDone: has_task: %s, task_accepted: %s, lock_thread_id: %d, command: %d\n",
				(has_task) ? "true" : "false",
				(task_accepted) ? "true" : "false", lock_thread_id, command);

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

		reset();
		done = true;
		return;
	}
};

