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

Is context concurrent safe? #5

Open
Dennis-Zhang-SH opened this issue Dec 2, 2022 · 2 comments
Open

Is context concurrent safe? #5

Dennis-Zhang-SH opened this issue Dec 2, 2022 · 2 comments
Labels
question Further information is requested

Comments

@Dennis-Zhang-SH
Copy link
Contributor

@rwestphal Hi, I wonder is context concurrent safe? In this crate it's all raw pointers and actually should not be impl send and sync, but I don't know if the c library is concurrent safe? If so I think it's fine.

By the way, would you mind establishing a little community of this crate? Or should I keep bother you with issues?

@rwestphal
Copy link
Member

@rwestphal Hi, I wonder is context concurrent safe? In this crate it's all raw pointers and actually should not be impl send and sync, but I don't know if the c library is concurrent safe? If so I think it's fine.

@Dennis-Zhang-SH The entire yang2-rs API should be thread-safe.

libyang's documentation assures thread-safety as long as certain rules are respected (single writer or multiple concurrent readers): https://netopeer.liberouter.org/doc/libyang/master/html/howto_threads.html

Since all yang2-rs functions that modify YANG contexts or data trees require mutable references, the borrow checker verifies at compile time if libyang's rules are being followed.

It shouldn't be possible, for example, to modify one data tree in one thread while reading the same data tree in another thread (or async task). The only way to do that would be by using a mutex or another synchronization primitive to ensure safe concurrent access.

Be mindful, however, that yang2-rs is only thread-safe as long as libyang withstands its promises.

By the way, would you mind establishing a little community of this crate? Or should I keep bother you with issues?

Please don't hesitate to open new issues whenever necessary, I do the same in the libyang repo ^^ I could open a Discord channel for this crate, but at this point that would be an overkill since there aren't many people using it.

@Dennis-Zhang-SH
Copy link
Contributor Author

@rwestphal thanks! Just finished reading context part of codes, your construction of Set is pretty decent, I am writing same ffi project on golang, and I have to say golang has a weaker type system, I find it hard to translate your code into golang code, even with its generics.

@rwestphal rwestphal added the question Further information is requested label May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants