Results 1 to 9 of 9

Thread: 2 questions about threads

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question 2 questions about threads

    Hi all, in my application I need to use two different threads:

    - The first thread only is executed one time, so, while it's running, the use can only abort it. I have implemented it with a boolean to know if the thread should abort the execution while it's running. This flag can be consulted by the thread while it's running and can be modified by a public method of the thread, all at the same time. I don't use any mutex while I make any of both operations but all works well. Anybody could tell me if it should be better if I use a mutex to lock this shared boolean variable when I consult/modify it?

    - The second thread processes some files and can be executed various times. To make it I've thought in 2 different ways: the first ones consists in using a flag to know if the thread should restart in the case that the thread is running and doing QThread::wait at the end of every execution (if it's doesn't need to restart) until it's aborted. But, I've thougth to implement a simpler version that consists in: when the thread is running and the user wants to add more files at the list of the files that the thread is currently processing, I lock the list with a mutex and append the new files at the end of the list. The thread finnishes when it reaches the end of the list. If the user wants to process new files and the thread is finished, it starts again. So with this new version the thread is started everytime (if it's not running), but I don't need the flag to rerstart it and to do wait as on the other version. The question is: what's the best way to implement this last version: in the main bucle of the thread consulting everytime the value count of the list (locking it before with a mutex) to know if it has reached its end, using a Qlistiterator removing the files that has ben processed until the list is empty, or something else? Another question is what's the best way to handle this list of files: with a stringlist containing the path of the files to process or with a list of QFiles to know the path of the files??

    Thanks
    Last edited by Dark_Tower; 18th March 2006 at 08:58.

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. Why do some QWidgets create own threads?
    By donglebob in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2010, 17:01
  3. Memory management questions (im new to Qt)
    By scarvenger in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 07:41
  4. Sql questions
    By Nb2Qt in forum Qt Programming
    Replies: 4
    Last Post: 15th February 2007, 22:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.