Results 1 to 4 of 4

Thread: Two QProcess object access to same function

  1. #1
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Two QProcess object access to same function

    Hi all,

    I have two QProcess objects. They run two different programs and their finished signals were handled.
    p1_handlefinished function is for first object and p2_handlefinished function is for second object.

    In p1_handlefinished and p2_handlefinished functions, i call a function myfunc;

    Should a lock(mutex) control accessing to myfunc or it doesn't need?

    I use QT4 on Linux.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Two QProcess object access to same function

    it depends on what myfunc() is doing.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Two QProcess object access to same function

    myfunc() has this prototype:
    void myfunc(QString str)

    This function appends to TextBrowser given str.

    I think that i should control calling myfunc by a lock, because only one instance of myfunc() exists and two QProcess objects should use it.
    Is it right?

    Please guide me completely or give me some references so that i read them myself.

    Thanks you very much.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Two QProcess object access to same function

    In general if you have a resource that can be accessed asynchronously at the same time from different threads, then you need to protect that resource with some mutual exclusion mechanism.
    So its not the function that needs to be mutexed, but the resource that is being accessed.
    In your case, actually, I think you don't need any mutexes, since your code lives in the main GUI thread.
    So your application is not threaded.
    The QProcess signals will not be called in parallel (even though each QProcess runs its own thread), since they are being handled by the QApplication event loop.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. The following user says thank you to high_flyer for this useful post:

    pronetin (20th February 2011)

Similar Threads

  1. Replies: 17
    Last Post: 11th April 2013, 09:35
  2. Replies: 4
    Last Post: 9th February 2010, 17:08
  3. How to access an object inside a privateslot
    By graciano in forum Qt Programming
    Replies: 7
    Last Post: 21st January 2009, 18:09
  4. Access an object stored in the list.
    By cbarmpar in forum General Programming
    Replies: 2
    Last Post: 21st September 2008, 20:19
  5. Access an object from another file.
    By cbarmpar in forum General Programming
    Replies: 1
    Last Post: 6th September 2008, 22:17

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.