Results 1 to 20 of 21

Thread: best threading solution?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: best threading solution?

    ok let me explain more, i want to know witch solution is better,
    first of all i know i need 30 units, but i have priority for switch task, i need my main thread run with download thread somehow simultaneity but if sleep time of main thread finished the download thread must go to sleep and wait to up until main thread again finish, so in your explanation we cant send a signal to a thread to sleep and call another thread to run, we can do this right? and if you say yes, how much this process better than use timers (in timers mode probably main thread dont run until download thread finish)

    we have a loop for main thread and we set a wait condition this is main loop

    while(1) {
    waitOn(); // check if Ui is in waiting state and if its not set uis and download to wait
    doWork();
    setOn() // set wait to free
    sleep(100);
    }

    and our problem is download thread, its not run sync so i dont know how implement it?
    and finally you dont say if i send my sample download command i a thread object and then call exec() function of that thread everything works in event loop of that thread right?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: best threading solution?

    You don't need any "download thread". It's not that there is a dwarf sitting there and constantly pulling a string that has your incoming data attached to it and which needs constant bugging to get to work. When the data arrives into the socket you will be informed about it, you can read the data (which takes literally miliseconds) and afterwards you can attend to other tasks. When more data arrives, you will again be informed about it, you will read the data and go back to the other task. On the other hand if you do it with threads, your thread will sit around doing nothing 99% of the time and you will have a lot of trouble in synchronizing all your threads.

    Your while() loop can be decomposed into a simple timer running with 100ms interval that triggers a slot that calls "doWork()".

    Here, read this: [wiki]Keeping the GUI Responsive[/wiki]
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    danics (14th August 2013)

Similar Threads

  1. Threading issue in DLL
    By CristonDK in forum Qt Programming
    Replies: 6
    Last Post: 15th June 2012, 18:07
  2. Threading with rsh and rcp
    By jaxrpc in forum Newbie
    Replies: 2
    Last Post: 4th June 2010, 11:50
  3. Threading...?
    By sekatsim in forum Qt Programming
    Replies: 12
    Last Post: 10th June 2008, 01:14
  4. Qt Threading
    By avh in forum Newbie
    Replies: 7
    Last Post: 30th May 2008, 20:20
  5. Sub-Threading
    By TheGrimace in forum Qt Programming
    Replies: 4
    Last Post: 7th June 2007, 16:38

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.