Could use some help from Rust Twitter on this one: I want to provide each thread with a Vec in a thread-local. Then from another thread I want to periodically take ownership of the thread-local vecs and swap them with empty ones. Is there a good pattern/lib for this?
-
Show this thread
-
I'm thinking I could make this work with an Arc<Mutex<Vec>> stored in the thread-local, and sending a clone over the the driver thread. But it feels like this should be doable using a compare-and-swap of sorts, but unsure how to make this work correctly. This should be common?
6 replies 0 retweets 0 likesShow this thread -
Replying to @yoshuawuyts
Are you making hazard pointers >.> My first question is what are you trying to achieve? The problem will be the monitor thread, and new thread creations. The monitor can't steal thread locals because it has a diff pthread key, unless you make it a global or ref in another struct
1 reply 0 retweets 1 like -
Replying to @Erstejahre @yoshuawuyts
The next issue is a shared struct with refs, may realloc and that will break any pointers.
1 reply 0 retweets 1 like -
Replying to @Erstejahre @yoshuawuyts
You could have a channel, and every thread at create sends an arc clone of its vec via the channel to the collecting thread, then your ability to do the swap inside the mutex would work.
1 reply 0 retweets 2 likes -
Replying to @Erstejahre
Ohh, yes -- I like this suggestion! And uhh, I hope I don't want hazard pointers? I don't know what they are but they sound like trouble haha.
1 reply 0 retweets 0 likes -
Replying to @yoshuawuyts
They are async garbage collection, like epoch baser reclaim. Subtely different properties. The channel idea also has a benefit that new threads deep into program exec still can participate, you arent bound to all threads neededing create at startup. You should consider ...
1 reply 0 retweets 1 like -
Replying to @Erstejahre @yoshuawuyts
How to signal that a thread has terminated though, but i guess the arc makes that safe given you wont use after free.
1 reply 0 retweets 1 like
Yeah, was thinking we could periodically check whether the strong_refcount == 1 and then evict when that's the case. Thanks so much for this! -- Been thinking about this most of the evening and this has been a great help!
-
-
Replying to @yoshuawuyts
Maybe its me but write it down and let it simmer in your mind. And im happy to review draft design doc too for comments :) good luck mate
0 replies 0 retweets 1 likeThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.