I have a class in my project which contains 4 vectors
m_vecA;
m_vecB;
m_vecC;
m_vecD;
These vectors can be accessed in different threads.I can use one critical section and protect all these vectors with it.
Or is it good idea to have 4 critical sections one for each resource? If I use one critical section for all resources I am seeing deadlock issue.
Generally is it good design to have one critical section for one resource or can we have one critical section per class?
Have 4 critical sections, but:
The trick is to always access (lock) them in the same order,
Otherwise you can deadlock if:
This cannot happen if you enforce a critical section ordering