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

Question about usage in async code #555

Closed
algermissen opened this issue Apr 15, 2023 · 2 comments
Closed

Question about usage in async code #555

algermissen opened this issue Apr 15, 2023 · 2 comments

Comments

@algermissen
Copy link

algermissen commented Apr 15, 2023

I am wondering how to properly use redb in multithreaded, async IO code (using Tokio). Can someone clarify the following?

Where and how many Database variables do I have to create? Do I create one in main and wrap it into an Arc<Mutex<..>> and clone it between threads? [Edit: I have just seen that Database and ReadTransactions are Send and Sync and WriteTransaction is Sync - I'll try to work from that and just share everything :-) ... but still it would be nice the hear what others think]

What should be shared across threads and what should not be shared? I saw the multithreaded benchmark, but that only works when I have control over what happens on which thread - in async IO code, that kind of control is not possible and I wonder how to integrate redb into async programs properly.

Any ideas or pointers?

Jan

@cberner
Copy link
Owner

cberner commented Apr 15, 2023

I haven't tried async, but redb does its own concurrency control, so you don't need the Mutex. Just Arc<Database> should work fine

@algermissen
Copy link
Author

Thank you - yes, seems to work just fine.

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