C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Proposal for extension std::mutex in ISO C++

From: anshul mittal <anshulmttl_at_[hidden]>
Date: Thu, 9 May 2024 11:23:20 +0530
Link to proposal : https://www.soft.amsbctech.com/page-3/

Press the download button on website.

On Thu, May 9, 2024 at 10:14 AM anshul mittal <anshulmttl_at_[hidden]> wrote:

> 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.
>
>

-- 
Anshul Mittal
Graduate Engineer Trainee
TVM signalling and transportation Systems

Received on 2024-05-09 05:53:35