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
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,
If you want to sync multiple thread then use QSemaphore.Originally Posted by Qt Doc
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.
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.
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,
QSemaphore docs contain a simple example of use of this class.
hi,
surely I read them but unfortunately I face the same error
Regards,
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.
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,
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.
Post the actual error and the actual code. Copy & paste, don't retype.
Bookmarks