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

Statment on thread safety missing in the documentation #718

Closed
franzhollerer opened this issue Oct 19, 2023 · 1 comment
Closed

Statment on thread safety missing in the documentation #718

franzhollerer opened this issue Oct 19, 2023 · 1 comment

Comments

@franzhollerer
Copy link

I miss some statement on thread safety in the documentation.

The commit 23313e8 removed the following text:

A libmodbus 'context' is thread safe and may be shared among as many application
threads as necessary, without any additional locking required on the part of the
caller.

and the file NEWS states for libmodbus 3.1.3 (2016-05-11):

- A libmodbus context isn't thread safe and won't be (closes #246).

But what does that mean specifically? Is the whole library not thread safe? Can I call library functions from different threads as long as I ensure that each thread operates on its own libmodbus context? Can I run a libmodbus server and libmodbus clients in different threads, or are or are there limitations to consider?

Being said, I think the documentation should have a section about thread safety.

@stephane
Copy link
Owner

On client side, yes, you can call library functions from different threads with one context by thread.
But if you write a Modbus server, the library doesn't help you to protect the mapping data (write access).

I could write a multi-threads version of https://github.com/stephane/libmodbus/blob/master/tests/bandwidth-client.c to illustrate it.

https://github.com/stephane/libmodbus/blob/master/tests/bandwidth-server-many-up.c

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