Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Making thread-local initialization explicit

Aperta
#99 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
wasm

Direzione di ricerca

La issue non indica file, test o punti di ingresso dell’implementazione. Inizia esaminando il modello esistente di thread-local-global e di istanziazione per thread della proposta, quindi determina l’API e la semantica di trap necessarie; il lavoro è completato quando il comportamento di istanziazione esplicita è specificato in modo coerente per istanze, thread, import ed export.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

One of the biggest problems identified with thread-local globals so far is the complexity and cost of ensuring they are initialized before they are used. One option we've considered is eagerly initializing the TLS for every instance when a new thread is created and eagerly creating the TLS for every thread when a new instance is created. This obviously scales very poorly. The other option we've considered is initializing TLS lazily upon entering a particular instance on a particular thread for the first time, but that would slow down all indirect calls because they would have to check whether they are crossing an instance boundary and need to initialize TLS.

I recently developed an idea for another option, which is to give up on ensuring that thread-local storage is available by the time it is accessed, and instead trap if it has not been explicitly initialized yet for the current thread. This was always going to be what happened when you called a thread-bound imported JS function before binding it on the current thread, so the new idea is to extend that pattern to thread-local globals as well. This semantics means that we need neither expensive eager initialization nor expensive lazy initialization, and ideally the initialization check on access could be made fast by using a trap handler.

The API for this explicit instantiation could be attached to some kind of shareable handle to a Module/Instance hybrid. This handle would be vended by a WebAssembly.Instance and could provide access to the shared exports of the instance on any thread, but it would only provide access to the unshared exports (if any) on a thread once it has been instantiated with the unshared and thread-local imports on that thread. The TLS would be allocated and initialized as part of this per-thread instantiation.

This would be essentially committing to the instance-per-thread model, at least as far as TLS is concerned. My hope is that this will be acceptable in the component model because the thread.spawn builtin will be able to identify any necessary thread-local imports from the thread-local reflection of the module/instance graph and can be specified as invoking the embedder API for doing the per-thread instantiation.

Lingua principale
WebAssembly
Stelle
97
Fork
6
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di WebAssembly/shared-everything-threads

Tutte le issue di WebAssembly/shared-everything-threads

Issue simili

Altre issue su Operating Systems

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.