Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Stopping a thread that tries to acquire a QSystemSemaphore

Stopping a thread that tries to acquire a QSystemSemaphore

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    koechr
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved