bitwiseworks / libcx

kLIBC Extension Library
GNU Lesser General Public License v2.1
11 stars 1 forks source link

tst-spawn2 sometimes fails #78

Closed dmik closed 4 years ago

dmik commented 4 years ago

While working on #77, I found that the following sometimes happens when running tst-spawn2 in debug mode several times in a raw (3 times is usually enough to trigger it):

LIBCx resource usage
--------------------
Reserved memory size:  2097152 bytes
Committed memory size: 65536 bytes
Heap size total:       65088 bytes
Heap size used now:    1960 bytes
Heap size used max:    6048 bytes
ProcDesc structs used now:       0
ProcDesc structs used max:       22
FileDesc structs used now:       0
FileDesc structs used max:       0
SharedFileDesc structs used now: 0
SharedFileDesc structs used max: 0
2944612b 01 ff 0000 Asrt: Assertion Failed!!!
2944612b 01 ff 0000 Asrt: Assertion Failed!!!
2944612b 01 ff 0000 Asrt: Function: <NULL>
2944612b 01 ff 0000 Asrt: Function: <NULL>
2944612b 01 ff 0000 Asrt: File:     D:/Coding/libcx/master/src/shared.c
2944612b 01 ff 0000 Asrt: File:     D:/Coding/libcx/master/src/shared.c
2944612b 01 ff 0000 Asrt: Line:     456
2944612b 01 ff 0000 Asrt: Line:     456
2944612b 01 ff 0000 Asrt: Expr:     !hst._used
2944612b 01 ff 0000 Asrt: Expr:     !hst._used
2944612b 01 ff 0000 Asrt: 1960
2944612b 01 ff 0000 Asrt: 1960
*** 2944612d ba81:01 shared.c:491:_DLL_InitTerm: hModule 1bd5, ulFlag 1
Exit code = 127
Elapsed time = 5.360000s

This is the stats from the last LIBCx process (the parent test case). It asserts because shared LIBCx memory heap is still in use (Heap size used now: 1960 bytes) while it must be completely free when the last LIBCx process is about to terminate.

It doesn't seem to be related to #77 directly as even with the old code it sometimes spits this. I suspect there is some shared memory leak somewhere or such. Most likely, during the multi-thtreaded testcase #12 which starts 25 processes simultaneously at 25 threads. This creates an insane race somewhere it seems and some struct is not properly released or the heap headers are not properly updated.

dmik commented 4 years ago

I've also once caught the following error:

ERROR: test 12: done threads 24, not 25

Looks like on SMP the thread done counter value is not updated for the main thread after being increased by one of the aux threads. I will use GCC atomics for both incrementing and reading it as a fix.