Inserita la QwaitCondition
[qmemory] / testThread.cpp
index 4c7dfb6..e3087e1 100644 (file)
@@ -5,7 +5,7 @@
 #include <QDateTime>
 TestThread::TestThread(QObject *parent):QThread(parent){
     colore=0;
 #include <QDateTime>
 TestThread::TestThread(QObject *parent):QThread(parent){
     colore=0;
-    attendiInputUtente=false;
+
     index=0;
     _score=0;
 
     index=0;
     _score=0;
 
@@ -16,8 +16,9 @@ TestThread::~TestThread(){
 
 }
 void TestThread::run(){
 
 }
 void TestThread::run(){
+    sleep(1);
     while(true){
     while(true){
-
+    mutex.lock();
     qsrand(QDateTime::currentDateTime().toTime_t());
     sequenza.append(qrand()%9);
     int i=0;
     qsrand(QDateTime::currentDateTime().toTime_t());
     sequenza.append(qrand()%9);
     int i=0;
@@ -28,18 +29,17 @@ void TestThread::run(){
     {
       emit generate(sequenza.at(i));
       qDebug()<<sequenza.at(i);
     {
       emit generate(sequenza.at(i));
       qDebug()<<sequenza.at(i);
-      msleep(500 - (_score*5));
+      msleep(500 - (_score*2));
       emit generate(sequenza.at(i));
       emit generate(sequenza.at(i));
-      msleep(500 - (_score*5));
+      msleep(500 - (_score*2));
       i++;
     }
     i=0;
       i++;
     }
     i=0;
-    attendiInputUtente=true;
     emit enableInterface();
     emit enableInterface();
+    attendiInputUtente.wait(&mutex);
+
+    mutex.unlock();
 
 
-    while(attendiInputUtente){
-        msleep(1);
-    }
     }
 
 
     }
 
 
@@ -47,7 +47,7 @@ void TestThread::run(){
 
 void TestThread::updateCaption(int inputUser){
 
 
 void TestThread::updateCaption(int inputUser){
 
-    if(attendiInputUtente){
+
 
         if(sequenza.at(index)==inputUser)
         {
 
         if(sequenza.at(index)==inputUser)
         {
@@ -55,7 +55,8 @@ void TestThread::updateCaption(int inputUser){
             _score++;
             emit score(_score);
             if(index==sequenza.size()){
             _score++;
             emit score(_score);
             if(index==sequenza.size()){
-                attendiInputUtente=false;
+                sleep(1);
+                attendiInputUtente.wakeAll();
                 index=0;
             }
         }
                 index=0;
             }
         }
@@ -64,14 +65,14 @@ void TestThread::updateCaption(int inputUser){
             _score=0;
             sequenza.clear();
             index=0;
             _score=0;
             sequenza.clear();
             index=0;
-            attendiInputUtente=true;
+            attendiInputUtente.wakeAll();
         }
         }
-    }
+
 }
 
 void TestThread::genera()
 {
 }
 
 void TestThread::genera()
 {
-        qDebug()<<"Init Emission";
-    attendiInputUtente=false;
+
+    attendiInputUtente.wakeAll();
 
 }
 
 }