Strange issue with mutex

Discussions and support about ChibiOS/RT, the free embedded RTOS.
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Location: Luleå, Sweden
Has thanked: 5 times
Been thanked: 6 times
Contact:

Strange issue with mutex

Postby Korken » Thu Jul 26, 2018 11:02 am

Hi all,

I have been adding mutexes to a piece of code, but I always get the following error when I have debug checks enabled:

Code: Select all

#0  chSysHalt (reason=reason@entry=0x800e5cc <func.7893> "chSchReadyI") at ../../src/ChibiOS/os/rt/src/chsys.c:207
#1  0x0800189a in chSchReadyI (tp=0x200056ac <mac_arbiter_+860>) at ../../src/ChibiOS/os/rt/src/chschd.c:223
#2  0x08002340 in chMtxUnlock (mp=mp@entry=0x20003edc <cmd_thd+2428>) at ../../src/ChibiOS/os/rt/src/chmtx.c:383


which happens in the following code:

Code: Select all

void send(uint64_t address, msg_t* msg, bool ack)
{
    _mtx.lock();
    _mac.send(address, msg, ack); // Something that needs protection
    _mtx.unlock();
   
    signalEvents(1); // Wakeup the MAC data pump
}


Is there something obvious that I am missing here in the use of my mutex?
send is being called inside a thread, and _mtx is part of a class.
Using ChibiOS 17.6.x.

Thanks!

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Strange issue with mutex

Postby Giovanni » Thu Jul 26, 2018 5:39 pm

Hi,

Most likely the problem is not in that code, it is about the unlocked thread already being in the READY or FINAL state. Maybe you have a thread terminating before releasing its mutexes or do something strange from an ISR.

Giovanni

User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Location: Luleå, Sweden
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: Strange issue with mutex

Postby Korken » Sun Jul 29, 2018 5:12 pm

Thanks Giovanni!

Perfect analysis as always :)


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 10 guests