multithreading - QThread state when at start() call thread is still running, but after is already not -


i have gui thread call write(qstring text) method of myqthread.
myqthread contains qmutex mutex , qlist<qstring> list. here write() , run() methods of myqthread:

void myqthread::write(qstring text) {      mutex.lock();      list.append(text); //point c      mutex.unlock();      start(); //point d }    void myqthread::run() {      mutex.lock();       while(!list.isempty())      {          qstring text = list.takefirst();          mutex.unlock();          ...//do          mutex.lock(); //point      }       mutex.unlock(); //point b }   

for example @ 'point a'. after point checking list , empty, going 'point b'. @ moment write() called, mutex still locked, gui thread waiting before 'point c'.
@ 'point b', after gui thread unlocked , start() ('point d') called.
possible, @ 'point d' myqthread still running?
in case calling of start() nothing. , newly added item in list not processed in run() until next call of write().
additional information. in case here 1 instance of myqthread.

yes. although probability of having race condition low, believe there's still chance qthread still sending signals , such. use qthread::wait before call start() sure.

edit: agreed on need consider qmutexlocker. code's going scary complicated pretty fast , can't sure you'll remember unlock every exit point.

edit2: perhaps qreadwritelock might more interesting in case?


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -