Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with SimpleSpinLock::lock causing spinLock() to block execution #34

Open
fs63 opened this issue Oct 15, 2021 · 1 comment
Open
Labels
bug Something isn't working under-investigation

Comments

@fs63
Copy link

fs63 commented Oct 15, 2021

Good evening Dave,

I've come across a problem in the "reentrantLocking.ino" example. Running it on an esp32 causes a near dealock situation.
The spinlock() method never gets a "free lock". Trying to wait for the provided iterations period (0xFFFFFFFFUL) makes the sketch block for a very long time ...

Changing 0xFFFFFFFFUL to a much lower value resolves the blocking situation of course.
But, I dont understand yet why "if (tm_internal::atomicSwapBool(&locked, false, true))" never comes truecin this special situation ... I need more research on that.

Details:

esp32: Terminal output
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4
276 Running inner task, before lock =0
276 locked synchronously, count=1
276 in nested function, lock count=2
276 Synchronous task done=100
527 Running inner task, before lock =0
527 locked synchronously, count=1
527 in nested function, lock count=2
527 Synchronous task done=200
778 Running inner task, before lock =0
778 locked synchronously, count=1
778 in nested function, lock count=2
778 Synchronous task done=300
1026 Before try lock, count=0
1026 We need to do async lock=0
1026 - got the lock=1
1029 Running inner task, before lock =1

The problem starts here (reentrantLocking.ino) with the new TaskMgrLock:
...
taskManager.scheduleFixedRate(250, [] {
log("Running inner task, before lock ", myLock.getLockCount());
// take the lock
TaskMgrLock locker(myLock);
log("locked synchronously, count", myLock.getLockCount());
nestedFunction(); ...

SimpleSpinLock,h
/**

  • Take the lock waiting the longest possible time for it to become available.
    */
    void lock() {
    spinLock(0xFFFFFFFFUL);
    }

SimpleSpinlock.ccp
...
if (tm_internal::atomicSwapBool(&locked, false, true)) { >> doesn't come true
...

@davetcc davetcc added bug Something isn't working under-investigation labels Oct 17, 2021
@davetcc
Copy link
Collaborator

davetcc commented Oct 17, 2021

Thanks for investigating this, I'll try and spin up the example on my ESP32 with a debugger and hopefully, I can recreate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working under-investigation
Projects
None yet
Development

No branches or pull requests

2 participants