QSystemSemaphore location on linux
-
I'm developing two applications on linux that have to be synchronized.
One application is regular C++ and a second is Qt.
The C++ application opens Posix named semaphore as sem_open(...), and the Qt opens QSystemSemaphore.
Tere is no strict order in opening the apps. Each one configured to connect to the existing semaphore in case it started as a second.
The C++ semaphore i can see at /dev/shm, but the Qt semaphore i can't found.
Where is it stored ?
If it's system resource, why it is not stored in standard place ? -
@alexsho
Hello,
If both applications are going to be synchronized through the same semaphore, then you have to pass the same name both for the the Qt app and your C++ program. Doing that will open only one semaphore, so why would you expect to see two separate primitives?Kind regards.
-
I do define the same name. I know that QT adds prefix and SHA hash to the name.
The problem that the applications still don't open same semaphore.
When i tested the applications as stand alone, to check where it creates (or looks for ) the semaphore, the C++ app creates its semaphore at the defined place: /dev/shm/, but the Qt app don't , or it is created in some another place.
As i understand, if i want the apps to open the same semaphore - it should be pointed to the same place.
When Qt app runs alone, the QSystemSemaphore object is creared without errors, but i can't found it in the system. -
I do define the same name. I know that QT adds prefix and SHA hash to the name.
The problem that the applications still don't open same semaphore.
When i tested the applications as stand alone, to check where it creates (or looks for ) the semaphore, the C++ app creates its semaphore at the defined place: /dev/shm/, but the Qt app don't , or it is created in some another place.
As i understand, if i want the apps to open the same semaphore - it should be pointed to the same place.
When Qt app runs alone, the QSystemSemaphore object is creared without errors, but i can't found it in the system.Suppose you've given
key
to Qt for the semaphore, then the file path is:QDir::tempPath() + "/qipc_systemsem_" + keyStripped + QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Sha1).toHex()
Where
keyStripped
is thekey
variable but every character that is not in the range a-z, A-Z is removed.Does that help?
-
I know that, this is the way the semaphore name is build on Qt.
I did the same on the C++ app, using external SHA1 function, and i get the same name.
The problem is that the default location of the Qt semaphore is probably differ from default system location.
I believe that two Qt applications will found each other, but in my case one app is general C++.
I solved the similar problem with QSharedMemory, but
in QSharedMemory there is a possibility to set NativeKey, then this will be the exact name of the created object. What i did is - i added the path prefix /dev/shm/ to the name and set it as Native.
That way i forced Qt to create (or found) the shared object in system standard place where the C++ app creates it.
In QSystemSemaphore there is no possibility to set Native Key, the Qt always adds its prefix, so i can't control the location of the object (i hope i'm wrong).
I must then try to change the location of the C++ semaphore. -
I know that, this is the way the semaphore name is build on Qt.
I did the same on the C++ app, using external SHA1 function, and i get the same name.
The problem is that the default location of the Qt semaphore is probably differ from default system location.
I believe that two Qt applications will found each other, but in my case one app is general C++.
I solved the similar problem with QSharedMemory, but
in QSharedMemory there is a possibility to set NativeKey, then this will be the exact name of the created object. What i did is - i added the path prefix /dev/shm/ to the name and set it as Native.
That way i forced Qt to create (or found) the shared object in system standard place where the C++ app creates it.
In QSystemSemaphore there is no possibility to set Native Key, the Qt always adds its prefix, so i can't control the location of the object (i hope i'm wrong).
I must then try to change the location of the C++ semaphore.The problem is that the default location of the Qt semaphore is probably differ from default system location.
The location Qt uses is
QDir::tempPath()
as written in my previous post.That way i forced Qt to create (or found) the shared object in system standard place where the C++ app creates it.
In QSystemSemaphore there is no possibility to set Native Key, the Qt always adds its prefix, so i can't control the location of the object (i hope i'm wrong).Not to my knowledge.
Kind regards.