Index: hvcontrol/src/HV.cc
===================================================================
--- hvcontrol/src/HV.cc	(revision 230)
+++ hvcontrol/src/HV.cc	(revision 264)
@@ -96,30 +96,39 @@
 
   unsigned char rbuf;
-  int ret;
+  int N, Ret = 0;
   fd_set SelectDescriptor;
-  
+  struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)};
+  
+  // === Lock file descriptor ===
+  if (lockf(fDescriptor, F_LOCK, 0) == -1) {
+	m->Message(m->ERROR, "Failed to lock file descriptor (%s)", strerror(errno));
+	return 0;
+  }
+
   // === Write data ===
-  if ((ret=write(fDescriptor, wbuf, Bytes)) < Bytes) {
-    if (ret == -1) m->Message(m->ERROR, "Could not write data to HV board (%s)", strerror(errno));
-    else m->Message(m->ERROR, "Could write only %d of %d bytes to HV board", ret, Bytes);
+  if ((N = write(fDescriptor, wbuf, Bytes)) < Bytes) {
+    if (N == -1) m->Message(m->ERROR, "Could not write data to HV board (%s)", strerror(errno));
+    else m->Message(m->ERROR, "Could write only %d of %d bytes to HV board", N, Bytes);
     ErrorCount++;
-    return 0;
+	goto ExitCommunicate;
   }
 
   // === Try to read until time-out ===
   FD_ZERO(&SelectDescriptor);   FD_SET(fDescriptor, &SelectDescriptor);
-  struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)};
   if (select(fDescriptor+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) {
     m->Message(m->ERROR, "Error with select() (%s)", strerror(errno));
-    return 0;
+	goto ExitCommunicate;
   }
   // Time-out expired?
-  if (!FD_ISSET(fDescriptor, &SelectDescriptor)) return -1;
+  if (!FD_ISSET(fDescriptor, &SelectDescriptor)) {
+  	Ret = -1;
+	goto ExitCommunicate;
+  }
 
   // Read error?    
-  if ((ret = read(fDescriptor, &rbuf, 1)) == -1) {
+  if (read(fDescriptor, &rbuf, 1) == -1) {
     m->Message(m->ERROR, "Read error (%s)", strerror(errno));
     ErrorCount++;
-    return 0;
+	goto ExitCommunicate;
   }
 
@@ -132,10 +141,18 @@
   for (int i=0; i<NUM_CHAINS; i++) Overcurrent[i] = (rbuf & (0X08 << i));
   ResetButton = (bool) (rbuf & 0X80);
-
-  return 1;
-}
-
-
-/* Reset HV board - uses TRead() and has same return values */
+  Ret =  1;
+
+  // === UnLock file descriptor ===
+  ExitCommunicate:
+  if (lockf(fDescriptor, F_LOCK, 0) == -1) {
+	m->Message(m->ERROR, "Failed to lock file descriptor (%s)", strerror(errno));
+	return 0;
+  }
+  
+  return Ret;
+}
+
+
+// Reset HV board
 int HVBoard::Reset() {
   
@@ -151,5 +168,5 @@
 
 
-/* Read status register - uses TRead() and has same return values */
+// Read status register
 int HVBoard::GetStatus() {
 
@@ -160,5 +177,5 @@
 
 
-/* Set high voltage - uses TRead() and has same return values */
+// Set high voltage 
 int HVBoard::SetHV(int chain, unsigned int channel, int hv) {
 
Index: hvcontrol/src/ProcessIO.cc
===================================================================
--- hvcontrol/src/ProcessIO.cc	(revision 230)
+++ hvcontrol/src/ProcessIO.cc	(revision 264)
@@ -30,5 +30,5 @@
 	{"rate", &ProcessIO::cmd_rate, 1, "<rate>", "Set status refresh rate in Hz"},
 	{"timeout", &ProcessIO::cmd_timeout, 1, "<time>", "Set timeout to return from read in seconds"},
-	{"reset", &ProcessIO::cmd_reset, 0, "", "Reset active bias board"},
+	{"reset", &ProcessIO::cmd_reset, 0, "", "Reset active bias boards"},
 	{"start", &ProcessIO::cmd_start, 0, "", "Start bias status monitor"},
 	{"stop", &ProcessIO::cmd_stop, 0, "", "Stop bias status monitor"},
@@ -53,9 +53,4 @@
   FirstBoard  = 0;
   LastBoard   = -1;
-
-  // Initialize mutex for thread synchronisation
-  if (pthread_mutex_init(&Mutex, NULL) != 0) {
-    Message(FATAL, "pthread_mutex_init() failed");
-  }
 
   // DIM console service used in PrintMessage()
@@ -109,8 +104,5 @@
   delete calib;
   delete ConsoleOut;	
-  free(ConsoleText);
-  
-  // Destroy mutex
-  if (pthread_mutex_destroy(&Mutex) != 0) Message(ERROR, "pthread_mutex_destroy() failed");
+  free(ConsoleText);  
 }
 
@@ -370,5 +362,11 @@
 void ProcessIO::cmd_reset() {
 
-  for (int i=FirstBoard; i<=LastBoard; i++) ResetBoard(i);
+  for (int i=FirstBoard; i<=LastBoard; i++) {
+	if (fHVBoard[i]->Reset() == 1) {
+	  PrintMessage("Reset of board %d\n", fHVBoard[i]->GetBoardNumber());
+	  PrintBoardStatus(i);
+	}
+	else PrintMessage("Error: Could not reset board %d\n",fHVBoard[i]->GetBoardNumber());
+  }
 }
 
@@ -527,10 +525,4 @@
 
   static bool Warned = false;
-  int Ret;
-
-  // Lock because command execution runs in different thread
-  if ((Ret = pthread_mutex_lock(&Mutex)) != 0) {
-	Message(FATAL, "pthread_mutex_lock() failed in commandHandler() (%s)", strerror(Ret));
-  }
 
   for (int i=0; i<NumHVBoards; i++) {
@@ -549,5 +541,5 @@
     if (fHVBoard[i]->ResetButton) {
       Message(INFO, "Manual reset of board %d", fHVBoard[i]->GetBoardNumber());
-      ResetBoard(i);
+	  fHVBoard[i]->Reset();
     }
     
@@ -558,27 +550,11 @@
     for (int j=0; j<NUM_CHAINS; j++) {
       if (fHVBoard[i]->Overcurrent[j]) {
-		Message(WARN, "Warning: Overcurrent in chain %d of board %d",j,fHVBoard[i]->GetBoardNumber());
-		ResetBoard(i);
+		Message(WARN, "Warning: Overcurrent in chain %d of board %d, resetting board",j,fHVBoard[i]->GetBoardNumber());
+		fHVBoard[i]->Reset();
       }
     }
-  }
-  
-  // Unlock
-  if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) {
-	Message(FATAL, "pthread_mutex_lock() failed in commandHandler() (%s)", strerror(Ret));
-  }
-
-}
-
-
-// Send reset to board and clear voltage arrays
-void ProcessIO::ResetBoard(int i) {
-    
-  if (fHVBoard[i]->Reset() == 1) {
-    PrintMessage("Reset of board %d\n", fHVBoard[i]->GetBoardNumber());
-    PrintBoardStatus(i);
-  }
-  else PrintMessage("Error: Could not reset board %d\n",fHVBoard[i]->GetBoardNumber());
-}
+  }  
+}
+
 
 
@@ -597,20 +573,9 @@
 
 
-// Command handling (mutex needed because of monitor thread)
+// Command handling
 void ProcessIO::commandHandler() {
 
-  int Ret;
-
-  if ((Ret = pthread_mutex_lock(&Mutex)) != 0) {
-	Message(FATAL, "pthread_mutex_lock() failed in commandHandler() (%s)", strerror(Ret));
-  }
-
   if ((getCommand()==Command) && (*(Command->getString()+Command->getSize()-1)=='\0')) {
-	SendToLog("Command '%s' from %s (ID %d)", Command->getString(), getClientName(), getClientId());
 	CommandControl(Command->getString());
-  }
-
-  if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) {
-	Message(FATAL, "pthread_mutex_unlock() failed in commandHandler() (%s)", strerror(Ret));
   }
 }
Index: hvcontrol/src/ProcessIO.h
===================================================================
--- hvcontrol/src/ProcessIO.h	(revision 230)
+++ hvcontrol/src/ProcessIO.h	(revision 264)
@@ -54,8 +54,5 @@
 	unsigned int fHVMaxDiff;
 
-	// Status variables  
 	pthread_t HVMonitor;       // exit function sends signal to these threads
-	pthread_mutex_t Mutex;
-
 	int NumHVBoards;
 	int FirstBoard;
@@ -71,5 +68,4 @@
 	bool RampVoltage(unsigned int, int, int, int);
 	void Monitor();
-	void ResetBoard(int);
 	void PrintBoardStatus(int);
 	
