Is is possible to create a semaphore accessable to both Windows and Qt applications?
-
I tried to create a named semaphore in a Windows application using following code:
m_hSemaphore = ::CreateSemaphore(NULL, 0, 100, "semaphore_test");
and in my Qt application I open a semaphore of the same name:
pSemaphore = new QSystemSemaphore(tr("semaphore_test"), 0, QSystemSemaphore::Open);
But when the semaphore is released in Windows application, in Qt application,
m_pSemaphore->acquire();
is still blocked, which means two applications are not accessing the samesemaphore.
Is there a way to make both applications access the same semaphore? The similar problem also exists in accessing shared memory in both Windows and Qt applications.
-
AFAIK Qt will decorate the Semaphore name, when using QSystemSemaphore().
You can use a tool such as ProcessExplorer to lookup the actual (native) name of the Semaphore...
http://technet.microsoft.com/de-de/sysinternals/bb896653.aspx
!http://imageshack.us/a/img690/9056/clipboard01yi.png(Screenshot from ProcessExplorer)!
Looks like the string "qipc_systemsem_" followed by a hash of the specified string is used ;-)
-
bq. Thank you very much for your help! Now I can make Windows application and Qt application use a same semaphore.
ProcessExplorer does not show shared memory used by a process, so making Windows application and Qt application use same shared memory is still a problem. Any ideas?The "shared" memory is nothing but a "memory mapped file", one that is backed by the system page file rather than by a file system file. Doesn't it show up under the file handles in ProcessExplorer?