Code Monkey home page Code Monkey logo

Comments (8)

itay-grudev avatar itay-grudev commented on June 18, 2024

Technically I found a workaround for releasing QSharedMemory after a process has crashed. On Windows it's not a problem, but on Linux by initializing it, then deleting forces the kernel to clean up the shared memory. This way the moment e initialize it again it's the first time it's initialized. Take a look at the code below.

#ifdef Q_OS_UNIX
// By explicitly attaching it and then deleting it we make sure that the
// memory is deleted even after the process has crashed on Unix.
d->memory = new QSharedMemory( d->blockServerName );
d->memory->attach();
delete d->memory;
#endif
// Guarantee thread safe behaviour with a shared memory block.
d->memory = new QSharedMemory( d->blockServerName );

Lockfiles on the other hand suffer from the same problem when an instance has crashed. Originally I tried implementing it with a lockfile, but found that to be too unreliable. But maybe we can give it another look.

Another option would be to handle the SingleAplication functionality completely through QLocalSocket. If there is a primary instance to connect to - use it. Otherwise create one. I think we can use the fact that you can't bind two programs to the same address for single instance protection.

from singleapplication.

itay-grudev avatar itay-grudev commented on June 18, 2024

One issue when using local sockets that I know of is if an app is busy and doesn't reply to the message in time. It can happen if the main event loop is blocked doing a task. To account for this we'll have to always start a separate thread for the SingleApplication QLocalServer.

from singleapplication.

emericg avatar emericg commented on June 18, 2024

I can confirm, it looks like SingleApplication doesn't work anymore with Qt 6.6...

from singleapplication.

jonaski avatar jonaski commented on June 18, 2024

@emericg Try #177

from singleapplication.

emericg avatar emericg commented on June 18, 2024

Works great on Linux, thanks, I'll try on other platforms tomorrow!

from singleapplication.

itay-grudev avatar itay-grudev commented on June 18, 2024

Fixed in #177 and released in v3.5.0.

from singleapplication.

itay-grudev avatar itay-grudev commented on June 18, 2024

Thanks @jonaski

from singleapplication.

jonaski avatar jonaski commented on June 18, 2024

Thiago just posted on the Qt dev mailing-list, see https://lists.qt-project.org/pipermail/development/2023-November/044680.html and https://codereview.qt-project.org/c/qt/qtbase/+/518039
Shortly summarized:
QSharedMemory is flawed by design and unless someone else steps up to fix QSharedMemory, it will be deprecated in Qt 6 and removed in Qt 7.
I would like to dig into this myself, but I'm already working 4-7 hours every day on open source work in addition to a full time job (which is non-Qt), and I'm already way behind on other stuff so I can't find the time now.

from singleapplication.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.