Inserita la QwaitCondition
[qmemory] / testThread.cpp
index fcdf34a..e3087e1 100644 (file)
@@ -5,7 +5,7 @@
 #include <QDateTime>
 TestThread::TestThread(QObject *parent):QThread(parent){
     colore=0;
-    attendiInputUtente=false;
+
     index=0;
     _score=0;
 
@@ -18,7 +18,7 @@ TestThread::~TestThread(){
 void TestThread::run(){
     sleep(1);
     while(true){
-
+    mutex.lock();
     qsrand(QDateTime::currentDateTime().toTime_t());
     sequenza.append(qrand()%9);
     int i=0;
@@ -35,12 +35,11 @@ void TestThread::run(){
       i++;
     }
     i=0;
-    attendiInputUtente=true;
     emit enableInterface();
+    attendiInputUtente.wait(&mutex);
+
+    mutex.unlock();
 
-    while(attendiInputUtente){
-        msleep(1);
-    }
     }
 
 
@@ -48,7 +47,7 @@ void TestThread::run(){
 
 void TestThread::updateCaption(int inputUser){
 
-    if(attendiInputUtente){
+
 
         if(sequenza.at(index)==inputUser)
         {
@@ -57,7 +56,7 @@ void TestThread::updateCaption(int inputUser){
             emit score(_score);
             if(index==sequenza.size()){
                 sleep(1);
-                attendiInputUtente=false;
+                attendiInputUtente.wakeAll();
                 index=0;
             }
         }
@@ -66,14 +65,14 @@ void TestThread::updateCaption(int inputUser){
             _score=0;
             sequenza.clear();
             index=0;
-            attendiInputUtente=true;
+            attendiInputUtente.wakeAll();
         }
-    }
+
 }
 
 void TestThread::genera()
 {
 
-    attendiInputUtente=false;
+    attendiInputUtente.wakeAll();
 
 }