Results 1 to 3 of 3

Thread: Mutlithreading with QThread and networking failing

  1. #1
    Join Date
    Nov 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Mutlithreading with QThread and networking failing

    Hi

    I am building an application which requires a certain number of threads to works. The main idea is to retrieve data from network sites at the same time with several working threads.
    Here is the main idea of the class definition
    Qt Code:
    1. class workingThread:public QThread
    2. {
    3. Q_OBJECT
    4. ThreadParams params;
    5. protected:
    6. void run();
    7. public:
    8. void SetParams(int param1,int param2,int etc)
    9. signals:
    10. void jobdone(int threadIndex)
    11. }
    To copy to clipboard, switch view to plain text mode 
    The idea is to have many instances of the same thread and for each thread it is a assigned a different task, in this case each task corresponds
    getting data from a web-site
    Qt Code:
    1. workingThread threads[10];
    To copy to clipboard, switch view to plain text mode 

    The slot receiving the signal JobDone reassigns the task to thread in this case it assigns a new site to retrieve data from, so if the user requires
    getting data from 100 different sites it will be distributed along the threads. At this point everything works fine.
    The problem comes when all threads reach the bottleneck function at the same time(curl_easy_perform) in which they retrieve data. Some of these threads are terminated while others skip code. In both cases the thread never send the signal jobdone nor the signal "finished". I do not know whether there is a problem with network connections and threads specially with the use of cURL functions. This happens equally in both Windows and Linux.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Mutlithreading with QThread and networking failing

    Does each thread has its own curl handle returned from curl_easy_init? I ask because the CURL manual says this about curl_easy_perform:
    You must never call this function simultaneously from two places using the same handle. Let the function return first before invoking it another time. If you want parallel transfers, you must use several curl handles.

  3. #3
    Join Date
    Nov 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Mutlithreading with QThread and networking failing

    yes, each call to curl has its own handle. The thread calls a function get_contents which has the CURL handle as local variable which is destroyed when the get_content functions ends.

Similar Threads

  1. networking
    By panyang in forum Newbie
    Replies: 1
    Last Post: 6th February 2011, 09:53
  2. Mutlithreading hangs gui
    By thahir1986 in forum Newbie
    Replies: 2
    Last Post: 28th September 2010, 10:10
  3. QT non-gui networking
    By MAbeeTT in forum Newbie
    Replies: 1
    Last Post: 21st August 2009, 19:47
  4. Qt-3 and networking
    By a550ee in forum Qt Programming
    Replies: 3
    Last Post: 3rd October 2006, 11:15
  5. Networking Help please
    By munna in forum Newbie
    Replies: 1
    Last Post: 17th September 2006, 09:35

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.