 	~KernelWrapper() {
 	}
 
+	void init() {
+		printf("KernelWrapper init\n");
+
+		is_monitoring = false;
+		done = false;
+		//pthread_mutex_init(&mutex_has_task, NULL);
+
+		reset();
+	}
+
 	void startMonitor() {
+		printf("KernelWrapper startMonitor\n");
 		pthread_create(&t_monitor, NULL, &KernelWrapper::thread, this);
 	}
 
 	static void *thread(void *context) {
-		volatile KernelWrapper *_this = ((KernelWrapper *) context);
+		KernelWrapper *_this = ((KernelWrapper *) context);
 
 		while (!_this->done) {
+			_this->is_monitoring = true;
 			//printf(
-			//		"MonitorThread has_task: %s, active_thread_id: %d, command: %d\n",
+			//		"KernelWrapper MonitorThread has_task: %s, task_accepted: %s, lock_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->task_accepted) ? "true" : "false",
+			//		_this->lock_thread_id, _this->command);
+
+			if ((!_this->has_task) && (_this->lock_thread_id >= 0)
 					&& (_this->command != UNDEFINED)) {
-				_this->has_task = true;
+				_this->task_accepted = true;
 				_this->sendCommand();
 			}
 		}
 		return NULL;
 	}
 
-	void sendCommand() volatile {
-
-		printf("MonitorThread sendCommand!\n");
+	void sendCommand() {
 
 		switch (command) {
 

	// initialize cuPrintf
	cudaPrintfInit();

	device_method<<<4, 1>>>(d_kernelWrapper);

	// display the device's output
	cudaPrintfDisplay();
	// clean up after cuPrintf
	cudaPrintfEnd();

	h_kernelWrapper->active_thread_id = 0;
	h_kernelWrapper->sendDone();

	// wait for SocketServer

public:
	volatile MESSAGE_TYPE command;
	volatile bool has_task;
	volatile bool task_accepted;
	volatile int lock_thread_id;
	volatile bool done;
	volatile bool is_monitoring;

	KernelWrapper() {
		init();
