Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a function to check if the instance is the only instance #91

Closed
wants to merge 1 commit into from

Conversation

ouuan
Copy link

@ouuan ouuan commented Feb 1, 2020

The function: bool SingleApplication::isSingleInstance()
Returns if the instance is the only running instance.

It is hard to check the number of running instances after a crash,
so this is an alternative solution for #89.

It uses a trick: the shared memory will be released after the last
instance detaches from it.

This closes #89.

The function: bool SingleApplication::isSingleInstance()
Returns if the instance is the only running instance.

It is hard to check the number of running instances after a crash,
so this is an alternative solution for itay-grudev#89.

It uses a trick: the shared memory will be released after the last
instance detaches from it.
@itay-grudev
Copy link
Owner

itay-grudev commented Feb 2, 2020

While this is a very creative solution, it creates a problem. For a small duration while the check is being performed, an instance can be started as a primary. So basically this function would be considered extremely dangerous and breaking the library.

I am much more inclined to accept a solution that pings existing instances to count how many are alive. I imagine it working like this:

  1. All instance sockets when using secondary instances are kept alive.
  2. You call countActiveInstances()
  3. It pings all sockets with a few bytes of random data
  4. Cleans up sockets with errors
  5. Counts sockets with a correct response
  6. Returns that number

@ouuan ouuan closed this Feb 5, 2020
@ouuan ouuan deleted the isSingleInstance branch February 5, 2020 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a function which returns the number of running instances
2 participants