Skip to content

Don't understand exercises/19_smart_pointers/arc1.rs #2175

Closed Answered by mo8it
stevebeauge asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry for the very late answer. I was very busy in the last couple of weeks.

You need to create a shared pointer of the vector of numbers, so Arc<Vec<u32>>.

Then, for each thread, you should clone the shared pointer before spawning the thread. This allows all threads to access the whole vector of numbers without worrying about the vector getting dropped while a thread still uses it. So no memory leak and no use-after-free.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mo8it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants