See also (same request, no standard solution):

https://stackoverflow.com/questions/69366623/stdscoped-lock-vector-of-mutexes
 

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

 

-----Ursprüngliche Nachricht-----
Von: Bharath S via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Di 07.02.2023 05:16
Betreff: [std-proposals] scoped_lock to support variable number of locks determined during runtime
An: std-proposals@lists.isocpp.org;
CC: Bharath S <bharath.sekarp@gmail.com>;
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?
 
Regards
Bharath
-- 
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals