See also (same request, no standard solution):

Why not create a custom mutex type, which delegates to the other mutices?


-----Ursprüngliche Nachricht-----
Von: Bharath S via Std-Proposals <>
Gesendet: Di 07.02.2023 05:16
Betreff: [std-proposals] scoped_lock to support variable number of locks determined during runtime
CC: Bharath S <>;
Hello everyone,
std::scoped_lock taking in just a variadic mutexes is restrictive. 
In one such scenario where there are jobs that are scheduled. These jobs has their own set of tasks to achieve. These task can work on a set of configurable inputs and outputs. The outputs of one of the task can be an input of another task under a different job that is scheduled. Since these are configurable, the mutexes creation is done during the process init and job scheduling. Hence there is no way to use scoped_lock which is an excellent addition to lock all or nothing mutexes that avoids deadlock. 
How about an RAII for scoped_lock which takes a std container of mutexes (or unique ptrs of mutexes). ? Is this a valid proposal? Am I missing something that is already there and easy to use like scoped lock?
Std-Proposals mailing list