Does it make sense to use std::shared_ptr < std::thread> ? The logic is simple: if thread is not needed, delete it, if new is required - realocate it. is there any way to compare this concept with pooled threads?
I do know the exact ammount of threads in my system(I develop Image processing algorithm, and I wanted to give each child of "algorithm" class an individual thread (maybe to make it private, then no shared_ptr is required), where this algorithm will be running, and idle this private thread if no image was provided. Is it a bad concept?
threadmakes little sense. Whatever is going tojoin()it should also own it.detach()is not normally recommended because process termination is brutal and rare and non-reproducible errors might be encountered because they're doing something critical when they're brutally culled. It's a classic bug that doesn't show up in relatively low load free running tests and then fouls in high load production just when you don't want it and have a real job debugging and fixing it. Essentially every detach() that isn't synchronized back is a race condition. We hate those.std::thread<>and that does offer options like cleanly evolving into from 1 to multiple threads in a future version. Say V1: processes colour image to grey scale in 1. V2: Cuts it up and does different pieces in parallel. That said one advantage of close coupling may be to achieve 25fps reliably. While separation is a good aim, it's still a matter of which lunch you want to pay for. All non-trivial real-time DIP application will be performance challenged at some point and ultimately bound by it.