A few tips:
- You probably should not be using
JoinSethere. Instead I recommendCancellationTokenfor being able to abort tasks, and optionallyTaskTrackerfor being able to wait for them to exit / wait for abort to finish. See graceful shutdown for more info on this. - As a general tip, trying to share something with
&'staticor&'static mutis always always the wrong way, every time.- In the case of
JoinSet, this type does not come with any utilities for sharing it. - You could still do so. Generally, I recommend using the actor pattern for sharing values for most cases.
- However, if you switch to using
TaskTracker, then it does come built-in with utilities for making it easier to share. Specifically, you can share it by cloning it. See the documentation for more info. The same applies to the cancellation token.
- In the case of
Even though I recommend you switch to TaskTracker instead of JoinSet, you can still benefit from the actor pattern with your application. I strongly recommend reading my article about it. Also, the talk about actors (linked in the article) was done after the article, and has more tips than the article itself, so I also recommend my talk.