Rust - Threading

Previously published

This article was previously published on A full index of these articles can be found here.

Now that I have my generic IdManager I’d like to use it from multiple threads. As I said, this code would normally be used for things like connection ids for network protocols and I’ve spent the past 20 years or so writing servers that use small numbers of threads to handle many thousands of connections with work for each connection being given to a thread from a thread pool to perform. This background gives me a logical next step; I’d like to use my ids in multiple threads. I’m hoping that the std::sync::Mutex<> I’m using to solve the “Interior Mutability Pattern” that I stumbled upon when adding my SmartId will help here, but I wont know for sure until I try.

Step one will be to play around with Rust’s std::thread and once I get that working I’ll try and use the IdManager with them, first using it from multiple threads at the same time and then passing id’s between threads; allocating on one and releasing on another.