Skip to content

Remove Mutex::_count #12976

Closed
Closed
@AriParkkila

Description

@AriParkkila

Description of defect

Mutex::_count should be removed or implemented properly.

Mutex class is not actually using _count for anything, but because it's updated without holding a lock that breaks implementation of the friend class ConditionVariable.

I guess the original idea behind _count was to implement recursive mutex, but it's not really needed as that's already handled (properly) in rtx_mutex.c. Also if ConditionVariable need to guarantee Mutex is non-recursive then simply deassert for osMutexRecursive attribute.

Target(s) affected by this defect ?

All with rtos.present.

Toolchain(s) (name and version) displaying this defect ?

All.

What version of Mbed-os are you using (tag or sha) ?

#0c4e50abb3fa1ec3d80f19c88ceefa106ff94e64

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

How is this defect reproduced ?

E.g. this code:

    Mutex m;
    Thread t;
    t.start([&m]() {
        while (1) {
            m.lock();
            m.unlock();
        }
    });

    ConditionVariable cv(m);
    while (1) {
        m.lock();
        cv.wait_for(0);
        m.unlock();
    }

... eventually it crashes:

++ MbedOS Error Info ++
Error Status: 0x80FF0144 Code: 324 Module: 255
Error Message: Assertion failed: _mutex._count == 1
Location: 0x1DEAF
File: ./mbed-os/rtos/source/ConditionVariable.cpp+52
Error Value: 0x0
Current Thread: main Id: 0x20004700 Entry: 0x1F3DB StackSize: 0x1FA0 StackMem: 0x200053F8 SP: 0x200071D4 
For more info, visit: https://mbed.com/s/error?error=0x80FF0144&tgt=MTB_LAIRD_BL654
-- MbedOS Error Info --

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions