Results 1 to 11 of 11

Thread: Using qsemaphor or qsystemsemaphore

  1. #1
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Using qsemaphor or qsystemsemaphore

    hi every body,

    I am new to qt and I have some question about the synchronization of threads:

    1. what is the difference of Qsemaphore and Qsystemsemaphore?

    2.Which one I can use and how I should use it?



    Thanks
    Regards,

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Using qsemaphor or qsystemsemaphore

    Quote Originally Posted by Qt Doc
    Like its lighter counterpart QSemaphore, a QSystemSemaphore can be accessed from multiple threads. Unlike QSemaphore, a QSystemSemaphore can also be accessed from multiple processes. This means QSystemSemaphore is a much heavier class, so if your application doesn't need to access your semaphores across multiple processes, you will probably want to use QSemaphore.
    If you want to sync multiple thread then use QSemaphore.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    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: Using qsemaphor or qsystemsemaphore

    Quote Originally Posted by havij000 View Post
    hi every body,

    I am new to qt and I have some question about the synchronization of threads:

    1. what is the difference of Qsemaphore and Qsystemsemaphore?

    2.Which one I can use and how I should use it?
    The difference is that QSystemSemaphore allows you to synchronize processes and not only threads at the cost of being more resource consuming and error prone (as one application can deadlock the semaphore for the other app effectively requiring a manual intervention like rebooting the machine). If you wish to synchronize threads of the same process, use QSemaphore.

    Semaphores are used to protect access to shared variables (usually some buffers) where potentially more than one thread can enter the critical section at once (as opposed to a mutex which is a binary semaphore only letting in a single thread). The semantics of a semaphore is that you can "lock" or "release" a specified number of resources preventing buffer overruns and underruns. In practice semaphores are much less frequently used than mutexes and wait conditions.
    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.


  4. #4
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using qsemaphor or qsystemsemaphore

    how should I use qsemaphor in my codes?

    I try too much but each time I face the same error:

    request for member acuire in "semaphor name" which is of non-class type 'Qsemaphore(int)'
    Regards,

  5. #5
    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: Using qsemaphor or qsystemsemaphore

    QSemaphore docs contain a simple example of use of this class.
    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.


  6. #6
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using qsemaphor or qsystemsemaphore

    hi,
    surely I read them but unfortunately I face the same error
    Regards,

  7. #7
    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: Using qsemaphor or qsystemsemaphore

    Your error is C++ related, you have a pointer to an object but you try to use it as if were an object. Replace the dot with an arrow or replace the pointer with an actual object.
    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.


  8. #8
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using qsemaphor or qsystemsemaphore

    no I dont thikn so.
    my error is not a C++ realated error, it is Qt related error.
    I really dont know where I should define the Qsemaphore and how I should use it??

    Regards,

  9. #9
    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: Using qsemaphor or qsystemsemaphore

    First of all there is nothing such as "Qsemaphore". There is only QSemaphore (with a capital S). So this is a C++ issue -- you're using a non-existing class.
    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.


  10. #10
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using qsemaphor or qsystemsemaphore

    Quote Originally Posted by wysota View Post
    First of all there is nothing such as "Qsemaphore". There is only QSemaphore (with a capital S). So this is a C++ issue -- you're using a non-existing class.

    Qsemaphore is just a typing mitake in the forum not the exat typing name that I use in mu codes
    Regards,

  11. #11
    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: Using qsemaphor or qsystemsemaphore

    Post the actual error and the actual code. Copy & paste, don't retype.
    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.


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.