Results 1 to 3 of 3

Thread: Execute a QProcess instead of a QThread

  1. #1

    Default Execute a QProcess instead of a QThread

    My application is written to run using a 3rd party DLL. The 3rd-party DLL is not thread safe. The application works as expected when each of (900+) threads execute one after another. When threads execute concurrently to QThreadPool::maxThreadCount - the application throws exceptions. I considered working around the limitation by executing each thread instead of within the context of a single application process but as a QProcess application. So for 10 tasks, the application would launch 10 QProcess processes (each QProcess working a single task).

    Note, regarding the application - the application can open 100s of task threads. I understand it is necessary to implement a processing throttle which mimics QThreadPool::maxThreadCount.

    In the spirit of "what can be done" are there thoughts / guidance on strategy to implement QProcess (or other approach) with Qt 5.12? If there is an example starter project - would greatly appreciate it.

    Very best regards,

    Tim Peer

  2. #2
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    363
    Thanks
    87
    Thanked 12 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Execute a QProcess instead of a QThread

    Hi Tim,

    this is an interesting little grit. Walking the 100s of QProcesses way sounds theoretically viable, but you always only know after you tried.
    I wonder why you would need to throttle the performance. You can spawn as many processes as you want and they will be distributed over the available cores by the underlying scheduler. What more needs to be done here?

    As an alternative to consider, are you able to identify the place of the call into the DLL that is not thread safe? You could protect that call with a QMutex and then still use a QThreadPool or QtConcurrent or any thread based approach.

    Bye,
    Cruz

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,324
    Thanks
    36
    Thanked 1,527 Times in 1,478 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Execute a QProcess instead of a QThread

    Well, one option would be to stay close to your current code and simply have each QRunnable of your thread pool run a QProcess.

    So if your current runnable code looks like this

    Qt Code:
    1. void MyRunnable::run()
    2. {
    3. some3rdPartyFunction(param1, param2, param3);
    4. }
    To copy to clipboard, switch view to plain text mode 
    then a QProcess based one would be a bit like this
    Qt Code:
    1. void MyRunnable::run()
    2. {
    3. QProcess process;
    4. process.start("helperExecutable", QStringList() << param1 << param2 << param3);
    5. process.waitForFinished(-1);
    6. }
    To copy to clipboard, switch view to plain text mode 
    with "helperExecutable" taking the commandline arguments to call some3rdPartyFunction in its main().

    Cheers,
    _

Similar Threads

  1. Execute system command from QProcess
    By graciano in forum General Programming
    Replies: 6
    Last Post: 20th February 2014, 10:05
  2. QProcess does not execute Automator app in OSX 10.6
    By Markus in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2010, 04:12
  3. How to use the QProcess to execute the Browser ?
    By eric0214 in forum Qt for Embedded and Mobile
    Replies: 7
    Last Post: 21st December 2009, 10:06
  4. How to use the QProcess to execute the Browser ?
    By eric0214 in forum Qt Programming
    Replies: 2
    Last Post: 17th November 2009, 06:18
  5. Replies: 1
    Last Post: 21st August 2009, 07:10

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.