Git Product home page Git Product logo

Comments (7)

abrown avatar abrown commented on July 26, 2024

I thought that _REENTRANT got set and then USE_LOCKS will be defined?

#ifdef _REENTRANT
#define USE_LOCKS 1
#endif

from wasi-libc.

TerrorJack avatar TerrorJack commented on July 26, 2024

Ah sorry, I missed the dlmalloc.c file! Yes, USE_LOCKS does get defined. Though it seems that currently spin locks is used in dlmalloc, which looks not ideal compared to futex based atomics.wait instruction?

from wasi-libc.

sbc100 avatar sbc100 commented on July 26, 2024

Yes we probably want to make sure USE_SPIN_LOCKS is not defined, so it will fallback to pthread locks.

from wasi-libc.

sbc100 avatar sbc100 commented on July 26, 2024

Here is where emscripten does that: https://github.com/emscripten-core/emscripten/blob/e64e3701c9c6d9fc2622fb34b92065971c326ed1/system/lib/dlmalloc.c#L29-L32

from wasi-libc.

TerrorJack avatar TerrorJack commented on July 26, 2024

I think there's an even bigger problem there; IIUIC pthread_mutex_lock in wasi-libc currently uses spinlock. We do have a futex-based lock at libc-top-half/musl/src/thread/__lock.c which gets used in some places, but not pthread lock itself. And also that futex lock doesn't take a timeout argument.

from wasi-libc.

sbc100 avatar sbc100 commented on July 26, 2024

As far as I can tell pthread_mutex_lock uses __wasilibc_futex_wait just like __wait.

Its just a rather indirect path:

pthread_mutex_lock -> __pthread_mutex_timedlock
__pthread_mutex_timedlock -> __timedwait
__timedwait -> __timedwait_cp
__timedwait_cp -> __futex4_cp
__futex4_cp -> __wasilibc_futex_wait

Is your analysis different to mine?

from wasi-libc.

TerrorJack avatar TerrorJack commented on July 26, 2024

Ah, that makes sense to me now! Thanks a lot for the clarification.

from wasi-libc.

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.