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

Recipe Series: Sharing data between threads #440

Open
AndyGauge opened this issue Jul 29, 2018 · 12 comments
Open

Recipe Series: Sharing data between threads #440

AndyGauge opened this issue Jul 29, 2018 · 12 comments

Comments

@AndyGauge
Copy link
Collaborator

Crates std, crossbeam_channel
Section 4.3 Sharing data between threads
- shared ownership with `Arc`
- shared stack with `crossbeam`
- mutable data with `Mutex`
- passing messages with `mspc` (crossbeam_channel)
@MagnumOpus21
Copy link

Can I take a shot at this? Any pointers are appreciated.

@AndyGauge
Copy link
Collaborator Author

You don't have to tackle the whole thing, if you want to attempt some of it, we can split it up.

@AndyGauge
Copy link
Collaborator Author

Also, I am not an expert in threading. In fact, I don't know how to recognize idiomatic threaded code. I'm sure we can pull in some other resources for this, but it might take some time.

@MagnumOpus21
Copy link

It makes sense to split this up.

@sn99
Copy link
Contributor

sn99 commented Oct 4, 2018

I could work this one but it might take a 4-5 days

j-haj added a commit to j-haj/rust-cookbook that referenced this issue Oct 10, 2018
@j-haj
Copy link
Contributor

j-haj commented Oct 11, 2018

Just as a heads up for anyone interested in this issue, I am working on a message passing example with crossbeam

@KodrAus
Copy link

KodrAus commented Oct 11, 2018

@j-haj Sounds good!

@MagnumOpus21 A good place to get started is this section of the Rust book. It has a lot of examples of using the std::thread and std::sync modules for concurrency. If you'd like to take a shot at one of the examples, like sharing data between threads with Arc, then we could provide some more support on the PR itself. It doesn't have to be complete when you open it!

crossbeam is a very subtle set of tools, so we'll probably want to keep any examples using crossbeam::epoch directly very simple, or just avoid them altogether in the cookbook, and rely on the higher-level pieces that have already been built over the top.

@MagnumOpus21
Copy link

Sorry, I ghosted for a few days, I had a lot of work to do. I will look into this and will try to open a PR by Sunday. :)

@j-haj
Copy link
Contributor

j-haj commented Oct 1, 2019

I have two examples for this: a simple single produce, single consumer example and a more complex example using the so-called ventilator pattern of a single produce to N consumers followed by N producers to a single consumer. I will have the PRs ready in a day or so.

@papac25
Copy link

papac25 commented Aug 19, 2020

how can u determine if you have been hacked

@papac25
Copy link

papac25 commented Aug 19, 2020

#- - - cschneid

@kkibria
Copy link

kkibria commented Feb 26, 2023

Hi all:
One of the problems is to share large data structure shared by many threads. However, data is updated less frequently, it is mostly read access and therefore optimized for reads. Linux employs RCU for similar requirements in its kernel. An example in rust for similar purpose would be useful. Also, an special case would be a single writer thread which can use further optimization. If you folks can put together examples with crossbeam that achieves RCU like data sharing that would be awesome! Just a thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants