Stopping a thread that tries to acquire a QSystemSemaphore



  • Hi there,

    I'm using QSystemSemaphore for interprocess-communication. Two processes shall acquire the systemsemaphore by turns.

    The flow of my application is as follows:
    -ProcessA creates the QSystemSemaphore with key "x" and acquires it.
    -ProcessB has a thread that creates the QSystemSemaphore with key "x". Since I'm using Windows, the QSystemSemaphore is not created but the already existing one is used.
    -the thread of ProcessB tries to acquire the QSystemSemaphore and blocks, until ProcessA releases the QSystemSemaphore.
    -ProcessA tries to acquire the QSystemSemaphore and blocks, until the thread of ProcessB releases the QSystemSemaphore.
    -the thread of ProcessB tries to acquire the QSystemSemaphore and blocks, until ProcessA releases the QSystemSemaphore.
    -...

    Everything works fine, but when I want to stop the thread, my application crashes. I can't figure out a way, to stop the thread from running, since the acquire-method blocks.

    The relevant parts of my code are:

    @
    //the method 'stopWorking' should stop the sharedMemoryLayer from grasping the QSystemSemaphore
    void Application::stopWorking() {

    if (thread->isRunning()) { //the sharedMemoryLayer runs within the thread 'thread'. I moved it there using 'moveToThread'
    thread->quit();
    thread->wait();
    }
    }
    @

    My question is:
    Is it possbible to stop that thread? If yes, how?
    Completly deleting it and creating a new object is absolutly acceptable, but even this crashed my application.

    Greetings and thanks in advance
    Christian


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.