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 |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
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.