whitecatboard / Lua-RTOS-ESP32

Lua RTOS for ESP32
Other
1.2k stars 221 forks source link

234881027:cannot start thread (No such file or directory) #142

Closed lu1210 closed 6 years ago

lu1210 commented 6 years ago

Hi, since last update i got this error message, sometime(?!)

12:46:38 printKD not started 234881027:cannot start thread (No su ch file or directory) f 1537 printKD.lua f 908 genKD.lua f 485 genKD.lc f 941 printKD.lc <-- file does exists

if thread.status(tprintKD) ~= 'running' then succ, tprintKD = pcall(thread.start, function() local suc, msg = pcall(dofile,'printKD.lc') if not suc then tprint(4,'printKD:',msg) end end) if succ then tThread.printKD = tprintKD else tprint(4,'printKD not started',tprintKD) os.ls('KD.') tprintKD = 0 end end

jolivepetrus commented 6 years ago

Mmmm .....

Which board? Using PSRAM?

lu1210 commented 6 years ago

I am using board ESP32 DEVKIT V1 from DOIT. Due the fact I don't know what PSRAM is, I think I have no PSRAM :- )

jolivepetrus commented 6 years ago

Hi @lu1210,

I imagine that "ESP32 DEVKIT V1" is your board type selected when building the firmware, and DOI is the board manufacturer, because ESP32 DEVKIT V1 is manufactured by Whitecat ;)

PSRAM is a feature available on some boards that expands the ESP32 RAM (max + 4 Mb) using a PSRAM chip, sharing the SPI bus with the flash.

jolivepetrus commented 6 years ago

Hi @lu1210,

Can't reproduce. Please, provide working example script that causes the issue in your board for testing.

lu1210 commented 6 years ago

HI, I'm sorry, but I cann't reproduce the error with a simple script. Can I send the whole scrips in a zip file to you?

jolivepetrus commented 6 years ago

Yes, of course.

Send to jolive@whitecatboard.org

jolivepetrus commented 6 years ago

@lu1210,

This is solved in https://github.com/whitecatboard/Lua-RTOS-ESP32/commit/2f618f170f48ce3f47f06d9adfeae036010ab7fa.

I have been able to reproduce the issue with the following script, with an empty test.lua file:

thread.start(function() while true do dofile("test.lua") tmr.delayms(1) end end)

thread.start(function() while true do dofile("test.lua") tmr.delayms(20) end end)

The problem was that spiffs was not configured to be thread-safe, nothing related with last esp-idf updates.

Please, try with your script.

lu1210 commented 6 years ago

it seems, it works perfect. Congratulation!!! I will start a night run with my script.

lu1210 commented 6 years ago

I am sorry. the error isn't solved :-(

17:56:56 printKD not started 234881027:cannot start thread (No su ch file or directory) f 941 printKD.lc f 1292 printKD.lua Free mem: 56072

lu1210 commented 6 years ago

By the way I don't understand the output of this script! Can you try this one. thread.start( function() -- local succ,msg,tsucc,tmsg while true do tid = thread.start( function() succ,msg = pcall(dofile,"test.lua") if not succ then print(msg) print('II',thread.status(tid)) end
end) tmr.delay(10) thread.list() end
end)

there are always same THID's ????????????? No entiendo nada

lu1210 commented 6 years ago

next I don't understand!

thread.start(function() print('HUBER') end,16384,20,1) stdin:1: 234881027:cannot start thread (No such file or directory) stack traceback: [C]: in field 'start' stdin:1: in main chunk [C]: in ?

jolivepetrus commented 6 years ago

Hi @lu1210,

About your question about that thid are equal ...

Extracted from posix 1.1 pthread spec:

Thread IDs are guaranteed to be unique only within a process. A thread ID may be reused after a terminated thread has been joined, or a detached thread has terminated.

The thing is that when you create the new thread every 10 seconds probably the previous thread is yet terminated and the thread id is reused. Internally, in the Lua RTOS pthread implementation the thread id is a pointer to a pthread structure created in the heap and released when the thread terminates, so there is a probability that when you create the new thread the same block in the heap is reused.

Other previous issues has been resolved in:

https://github.com/whitecatboard/Lua-RTOS-ESP32/commit/7ea5a4373b95e6a9fc621316b5216758cdec0d0f

https://github.com/whitecatboard/Lua-RTOS-ESP32/commit/99c4be328bb788bfa0def8616aa7656cc4f33b4a

lu1210 commented 6 years ago

You are right, but in my understanding, there could'nt be the sane THID at the same time(see example) or thread.list goes wrong.


       |        |                  |        |      |      |            STACK               

THID | TYPE | NAME | STATUS | CORE | PRIO | SIZE FREE USED

1073569396 lua Audit run 0 20 10216 5520 4696 ( 45%)
1073478684 lua lua_main run 0 20 20480 12004 8476 ( 41%)
1073458328 lua Hackler run 1 20 16384 8036 8348 ( 50%)
1073501232 lua Receive run 1 21 8192 6544 1648 ( 20%) < ---------- 1073501232 lua Recovery run 1 17 16384 11952 4432 ( 27%) < ---------- 1073601992 lua lua_thread run 1 20 16384 13668 2716 ( 16%)
1073517396 lua lua_thread run 1 20 16384 13672 2712 ( 16%)
1073515572 lua lua_thread run 1 20 16384 14600 1784 ( 10%)
1073462516 lua lua_thread run 1 20 16384 12460 3924 ( 23%)

jolivepetrus commented 6 years ago

@lu1210,

Please, try again with the last commit. The only apparent reason for the duplicate 1073501232 thid is that one of the threads already is deleted, but it's TCB is not free yet by FreeRTOS.

In recent commits deleted TCB are not considered in list.

lu1210 commented 6 years ago

hi jolivepetrus, with new firmware update all works perfect:-)