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

What's the best practice about multiple subscribers and publishers? #555

Open
fwxnn opened this issue Dec 20, 2024 · 2 comments
Open

What's the best practice about multiple subscribers and publishers? #555

fwxnn opened this issue Dec 20, 2024 · 2 comments

Comments

@fwxnn
Copy link

fwxnn commented Dec 20, 2024

I met a question recently. When I use the same object lcm::LCM lcm to subscribe and publish different channels in the same time, it's easy to cause core dump. e.g.

"""
lcm::LCM lcm;
lcm.subscribe("channel A", …)
lcm.subscribe("channel B", …)

while(lcm.good())
{
lcm.publish("channel A", …)
lcm.handle();
lcm.publish("channel B", …)
lcm.handle();
}
"""

My test platform is ubuntu 18.04 with x64 architecture. Looking forward to your early reply since lcm is planned to ba applied to our true program. thx!

@nosracd
Copy link
Contributor

nosracd commented Dec 20, 2024

Is it possible the segfaults are occurring in the callbacks you're registering? As far as I can tell, the pseudocode you posted should work fine. For example, this Python script:

import lcm

def callback(channel, message):
    print(f'Received message on channel {channel}')

lcm_object = lcm.LCM()
lcm_object.subscribe('channel A', callback)
lcm_object.subscribe('channel B', callback)

lcm_object.publish('channel A', bytes(0))
lcm_object.handle()

lcm_object.publish('channel B', bytes(0))
lcm_object.handle()

produces the output:

Received message on channel channel A
Received message on channel channel B

@fwxnn
Copy link
Author

fwxnn commented Dec 24, 2024

Indeed it works! I have found the question I made and LCM works quite well! THX

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

No branches or pull requests

2 participants