 
 	// getValue for each Thread
 	do {
-		atomicExch(&d_kernelWrapper->active_thread_id, thread_id);
+
+		atomicExch((int *) &d_kernelWrapper->active_thread_id, thread_id);
+		//__threadfence_system();
 
 		if (d_kernelWrapper->active_thread_id == thread_id) {
 			accessed = true;

		done = false;
	}

	__device__ __host__ int getValue(int val) {

		command = GET_VALUE;
		param1 = val;

		// wait for socket communication
		while (true) {

class KernelWrapper {
private:
	pthread_t t_monitor;
	//pthread_mutex_t mutex_result_available;
	//pthread_mutex_t mutex_has_task;
	//pthread_cond_t new_command_cv;
	volatile int param1;
	volatile bool result_available;
	volatile int result_int;
	//string resultString;

public:
	volatile MESSAGE_TYPE command;
	volatile bool has_task;
	volatile int active_thread_id;
	volatile bool done;

	KernelWrapper() {
		init();
