Coder Social home page Coder Social logo

Comments (7)

HongxiaWangSSSS avatar HongxiaWangSSSS commented on July 26, 2024 1

yes, it worked!!
Thank you @anchao for the quick action.👍
Let me close the issue~

from nuttx.

anchao avatar anchao commented on July 26, 2024

Hi, @HongxiaWangSSSS
Do you have other test cases that can reproduce this issue?

joininfo will not be released until the task group is destroyed:
https://github.com/apache/nuttx/blob/master/sched/pthread/pthread_release.c#L60-L80

from nuttx.

anchao avatar anchao commented on July 26, 2024

I tried to run the test code in the C native, the test case works as expected:

https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/iwasm/libraries/lib-wasi-threads/stress-test/stress_test_threads_creation.c#L52

  1. replace the test code:
$ git status
HEAD detached at origin/master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   examples/hello/hello_main.c

no changes added to commit (use "git add" and/or "git commit -a")
  1. remove the wasi api:

https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/iwasm/libraries/lib-wasi-threads/stress-test/stress_test_threads_creation.c#L67-L71

  1. run the test demo:

./tools/configure.sh sabre-6quad/nsh

$ qemu-system-arm -semihosting -M sabrelite -m 1024 -smp 4 -nographic -kernel ./nuttx

NuttShell (NSH) NuttX-10.4.0
nsh> hello
Spawning stress test is 10% finished
Spawning stress test is 20% finished
Spawning stress test is 30% finished
Spawning stress test is 40% finished
Spawning stress test is 50% finished
Spawning stress test is 60% finished
Spawning stress test is 70% finished
Spawning stress test is 80% finished
Spawning stress test is 89% finished
Spawning stress test finished successfully executed 50000 threads with retry ratio 1.000160
nsh> free
                   total       used       free    maxused    maxfree  nused  nfree
        Umem: 1065190036      10132 1065179904    1247684 1065166264     24      3
nsh> hello
Spawning stress test is 10% finished
Spawning stress test is 20% finished
Spawning stress test is 30% finished
Spawning stress test is 40% finished
Spawning stress test is 50% finished
Spawning stress test is 60% finished
Spawning stress test is 70% finished
Spawning stress test is 80% finished
Spawning stress test is 89% finished
Spawning stress test finished successfully executed 100000 threads with retry ratio 1.000120
nsh> free
                   total       used       free    maxused    maxfree  nused  nfree
        Umem: 1065190036      10132 1065179904    1247684 1065166264     24      3
nsh> 

from nuttx.

HongxiaWangSSSS avatar HongxiaWangSSSS commented on July 26, 2024

Hi,

Thank you for the test !!!🙇‍
Yes, I also found the exit and memory leak only occurs when built this sample into WASM/AOT, and during the run time, it continued malloc until exited and never released.
Maybe I should investigate the pthread_join's implementation in WASI-LIBC side.
Anyway, thank you for your explanation~ If there is any progress I will update.

BR,
Hongxia

from nuttx.

anchao avatar anchao commented on July 26, 2024

@HongxiaWangSSSS

I probably know the root cause. after the introduction of #11898, the detached thread will not destroy the joininfo. In your test case, a large number of pthreads will be created with detached attribute, so there will be many joininfo pending in the task group,each of joininfo is to ensure that pthread_join() could gets the correct return value:

joining a detached/canceled thread should return EINVAL, not ESRCH

apache/nuttx-apps#2329

https://github.com/apache/nuttx/blob/master/sched/pthread/pthread_join.c#L92-L102

since many of joininfo will consume too much memory, I think this is not friendly to embedded MCU devices,maybe we can keep the semantics before #11898 was introduced, @xiaoxiang781216 how do you think?

from nuttx.

xiaoxiang781216 avatar xiaoxiang781216 commented on July 26, 2024

thread should release joininfo after detaching, since nobody will call pthread_join.

from nuttx.

anchao avatar anchao commented on July 26, 2024

@HongxiaWangSSSS please try PR #12106

from nuttx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.