Disponible
amalgame-threading
Mutex, Channel, ThreadSpawn — wrap pthread.
Vue d'ensemble
Primitives de concurrence : threads, mutex, channels FIFO bornés. Wrap pthread sous Linux et macOS ; sous Windows, MSYS2 / MinGW fournit pthread-w32. Les threads natifs Windows sont prévus en v2. Chaque thread est enregistré auprès du GC Boehm.
Caractéristiques
- ✓
Threading.ThreadSpawn(fn, arg),ThreadJoin(t),ThreadSleep(ms),ThreadIsAlive(t) - ✓
Threading.MutexNew(),MutexLock(m),MutexUnlock(m),MutexTryLock(m) - ✓
Threading.ChannelNew(capacity)FIFO borné :ChannelSend,ChannelReceive,ChannelClose, et des versionsTry…non bloquantes - ✓Condition variables internes pour
Channel - ✓Enregistrement GC-safe via
GC_pthread_create
Exemple
Exemple minimal d'utilisation — recopiable tel quel après l'install.
amc package add threading
import Amalgame.Threading
class Program {
public static void Main() {
let ch: AmalgameChannel = Threading.ChannelNew(16) // FIFO borné
let worker = (n: int) => {
var i: int = 1
while (i <= n) {
Threading.ChannelSend(ch, i * i)
i = i + 1
}
Threading.ChannelClose(ch)
return 0
}
let t = Threading.ThreadSpawn(worker, 10) // lance worker(10) sur un nouveau thread
while (true) {
let v: int = Threading.ChannelReceive(ch)
if (v == 0 && Threading.ChannelIsClosed(ch)) { break } // 0 : fermé et vide
Console.WriteLine(String_FromInt(v))
}
Threading.ThreadJoin(t)
}
}
En bref
- Licence : Apache-2.0
- Installation :
amc package add threading - Code source : amalgame-lang/amalgame-threading
- Index officiel : amalgame-lang/packages-index