I have a class, let's call it Foo foo, which holds data that is useful to multiple threads. These threads may call read and write operations (e.g. foo->emplace(something)) which I protected by a mutex inside Foo and added mutex locks to the operations. Here's where I'm uncertain when it comes to implementation. I have to add another piece of shared information to foo where I have to call foo->emplace2(somethingElse) and this will store somethingElse in a std::set but this should only be stored for a minute.
What is the right approach to this? Do I create a new thread from inside foo whenever emplace2 is called and inside this thread emplace, sleep for 60 seconds, then erase? I feel like there is a better way than creating lots of threads every time emplace2 is called.
Not looking for code, just general implementation advice.
Aucun commentaire:
Enregistrer un commentaire