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

One NodeShared per process #139

Closed
wants to merge 4 commits into from

Conversation

joxoby
Copy link
Contributor

@joxoby joxoby commented May 15, 2020

@joxoby joxoby requested a review from caguero as a code owner May 15, 2020 18:47
@joxoby joxoby changed the title One NodeShared per process (#137) One NodeShared per process May 15, 2020
// Create a new instance of NodeShared if the process has changed
// (maybe after fork?) so the ZMQ context is not shared between different
// processes.
if (instance == nullptr || instance->pUuid != Uuid().ToString())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to make this Uuid comparison faster

@caguero
Copy link
Collaborator

caguero commented May 25, 2020

Thanks for the contribution. I've been doing some testing and I have two major concerns:

  1. As far as I understand, the new implementation of NodeShared()::Instance() doesn't behave as a singleton anymore. Two calls to Instance() within the same process are going to instantiate two NodeShared objects which defeats the purpose of the singleton.
if (instance == nullptr || instance->pUuid != Uuid().ToString())

The expression instance->pUuid != Uuid().ToString() is going to evaluate to true for every new Instance() call. This breaks the current functionality of the library. The basic publisher/subscriber example doesn't work anymore.

  1. Assuming that the patch would behave as a singleton, I don't think is thread safe anymore. However, doing the static initialization of instance directly is guarantee to be thread-safe.

@joxoby
Copy link
Contributor Author

joxoby commented May 25, 2020

Hi Carlos,

  1. You're right, it was a confusion of mine regarding Uuid. What I meant to codify was something like
if (instance == nullptr || instance->pid != getpid())
  1. We can easily add a lock_guard. WDYT?

@caguero
Copy link
Collaborator

caguero commented Jun 1, 2020

instance == nullptr || instance->pid != getpid()

Do you mind to update this pull request with a working prototype? It'll help to wrap my head around it. Thanks!

@joxoby
Copy link
Contributor Author

joxoby commented Jun 5, 2020

With the last change, the ignition-transport test are passing but it does cause problems with ign-gazebo. Will update.

@caguero
Copy link
Collaborator

caguero commented Jun 29, 2020

I'll decline this pull request for now until there's a better patch that keeps all tests and examples working. Feel free to reopen if that's the case.

@caguero caguero closed this Jun 29, 2020
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.

2 participants