Hello to all!
I encounter a problem in a program using an FTDI USB interface. I want to control the FTDI4232 (in MPSSE mode but this has no relevance to the error). For this I started 2 thread to read the FTDI device, one thread for each serial chanel of the USB interface in the FTDI. I locked the reading/writing function with mutexes because they are imported from the FTDI driver DLLs. But something I have to do wrong because after 50-50 iteration in the do {...} cycle inside the thread the program quit without any reason or debug info:
"The program has unexpectedly finished.
C:\I2C\Scanner\I2C_scanner-build-desktop-Qt_4_7_4_for_Desktop_-_MSVC2008__Qt_SDK__Debug\debug\I2C_scanner.exe exited with code -1073741819"

I want to run the treads "forever" and the do {..} cycle waits for the data input from the serial device.
I declare the thread objects like:

Qt Code:
  1. class readdatabit : public QThread
  2. {Q_OBJECT
  3. public:
  4. void run();
  5. signals:
  6. void change(void);
  7. private:
  8.  
  9. };
  10.  
  11. class readclockbit : public QThread
  12. {Q_OBJECT
  13. public:
  14. void run();
  15. signals:
  16. void change(void);
  17. private:
  18.  
  19. };
To copy to clipboard, switch view to plain text mode 

I instantiate and start them like below. I mention that none of the signals are fired before the crash.

Qt Code:
  1. readdatabit *readb=new readdatabit();
  2. readclockbit *clockb=new readclockbit();
  3. connect(readb,SIGNAL(change(void)),this, SLOT(FTDI_signalchange(void)));
  4. connect(clockb,SIGNAL(change(void)),this, SLOT(FTDI_signalchange(void)));
  5. readb->start();
  6. clockb->start();
To copy to clipboard, switch view to plain text mode 

One of the run() part are below, the not included other run() are the same, only difference is that they work on two different chanels in the FTDI serial USB interface. I mention here that most of the variables are global but none of the variables of the threads are modifyed outside of the thread and the function in the "lockers" are imported from a DLL (driver).

Qt Code:
  1. void readclockbit::run()
  2. {qDebug("thread readclockbit entered");
  3. if (clock==true){
  4. dwNumBytesToSendB = 0;
  5. byOutputBufferB[dwNumBytesToSendB++] = 0x89;
  6. //Wait On I/O Low 0x89,This will cause the controller to wait until GPIOL1 (JTAG) or I/O1 (CPU) is low.
  7. //Once it is detected as low, it will move on to process the next instruction.
  8. byOutputBufferB[dwNumBytesToSendB++] = 0x81;
  9. mutex.lock();
  10. ftStatusB = FT_Write(ftHandleB, byOutputBufferB, dwNumBytesToSendB, &dwNumBytesSentB);
  11. mutex.unlock();
  12. do//*********************************** CRASH SOMEWHERE IN THIS DO CYCLE !!!!!!!
  13. { qDebug("Waiting for CLOCK fall in thread B.");
  14. usleep(1);
  15. mutex.lock();
  16. ftStatusB = FT_GetQueueStatus(ftHandleB, &dwNumBytesToReadB);
  17. mutex.unlock();
  18. if (ftStatusB == FT_OK){
  19. qDebug("CLOCK queue OK in thread B, fall") ;}
  20. else {qDebug()<<"CLOCK queue FAILED in thread B, fall!!! Error:"<<ftStatusB;
  21. }
  22. } while ((dwNumBytesToReadB== 0) && (ftStatusB == FT_OK));
  23. mutex.lock();
  24. ftStatusB = FT_Read(ftHandleB, &byInputBufferB, dwNumBytesToReadB, &dwNumBytesReadB);// Read out the data from input buffer
  25. mutex.unlock();
  26. clockold=true;
  27. clock=false;
  28. }
  29.  
  30. else {
  31. dwNumBytesToSendB = 0;
  32. byOutputBufferB[dwNumBytesToSendB++] = 0x89;
  33. //Wait On I/O High 0x88 This will cause the MPSSE controller to wait until GPIOL1 (JTAG) or I/O1 (CPU) is high.
  34. //Once it is detected as high, it will move on to process the next instruction.
  35. byOutputBufferB[dwNumBytesToSendB++] = 0x81;
  36. mutex.lock();
  37. ftStatusB = FT_Write(ftHandleB, byOutputBufferB, dwNumBytesToSendB, &dwNumBytesSentB);
  38. mutex.unlock();
  39. do//*********************************** CRASH SOMEWHERE IN THIS DO CYCLE !!!!!!!
  40. { qDebug("waiting for CLOCK rise in thread B");
  41. usleep(1);
  42. mutex.lock();
  43. ftStatusB = FT_GetQueueStatus(ftHandleB, &dwNumBytesToReadB);
  44. mutex.unlock();
  45. if (ftStatusB == FT_OK){
  46. qDebug("CLOCK queue OK in thread B, rise") ;}
  47. else {qDebug("CLOCK queue FAILED in thread B, rise!!! Error: "+ftStatusB);
  48. }
  49. } while ((dwNumBytesToReadB == 0) && (ftStatusB == FT_OK));
  50. mutex.lock();
  51. ftStatusB = FT_Read(ftHandleB, &byInputBufferB, dwNumBytesToReadB, &dwNumBytesReadB);// Read out the data from input buffer
  52. mutex.unlock();
  53. clockold=false;
  54. clock=true;
  55. }
  56. change();
  57. }
To copy to clipboard, switch view to plain text mode 

Thanks in advance all answers!!!