Repository navigation
Don't understand exercises/19_smart_pointers/arc1.rs #2175
|
I don't understand this exercice. I don't know what I'm supposed to do. What should child number be ? At first, I thought I have to split the works into 8 "child vectors", but the spawned thread already contains the logic to split in 8 the process. thanks for clarification |
Answered by
mo8it
Jan 2, 2025
Replies: 1 comment
|
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 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. |
0 replies
Answer selected by
mo8it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.