Date: Thu, 9 May 2024 10:14:20 +0530
I am Anshul Mittal building webserver using C++. I have found a new
solution to a problem.
When a single thread tries locking on the same mutex std::mutex it creates
a deadlock. This situation can arise in some projects and it arose for me.
I am sending this proposal to update the specification to incorporate this
new technology.
The std::mutex should not allow locking if the same thread is requesting
the lock on same mutex.
You can get thread id using std::this_thread::get_id().
Eg.
Current situation :
mutex mut;
mut.lock();
mut.lock();
This creates a deadlock.
By putting thread id check the deadlock is prevented. I call this
SampleMutex.
SampleMutex mut;
mut.lock();
mut.lock(); // This lock should not happen and no deadlock created.
solution to a problem.
When a single thread tries locking on the same mutex std::mutex it creates
a deadlock. This situation can arise in some projects and it arose for me.
I am sending this proposal to update the specification to incorporate this
new technology.
The std::mutex should not allow locking if the same thread is requesting
the lock on same mutex.
You can get thread id using std::this_thread::get_id().
Eg.
Current situation :
mutex mut;
mut.lock();
mut.lock();
This creates a deadlock.
By putting thread id check the deadlock is prevented. I call this
SampleMutex.
SampleMutex mut;
mut.lock();
mut.lock(); // This lock should not happen and no deadlock created.
Received on 2024-05-09 04:44:34