Nim keeles on lisatud YRC — lĂ”imede ohutu tsĂŒkliliste viidete koguja.

Andreas Rumpf (Araq), Nim programming language's author, announced a new memory management algorithm YRC (pronounced as "Ürk"), which addresses one of the key issues of existing mechanisms in Nim: the inability to properly handle cyclic references crossing thread boundaries.

Before the introduction of YRC, the memory management algorithms proposed in Nim had several limitations: ARC did not support multithreading or cycle handling; Atomic ARC was thread-safe but did not process cyclic references; ORC could handle cyclic references but only correctly within a single thread (using shared references between threads led to memory leaks).

The proposed YRC combines thread safety and cycle handling across threads by using a combined approach: for acyclic data, atomic reference counting is applied, while for cyclic data, a write barrier is activated only when pointer assignments are made. In the proposed implementation: the collector runs as needed (no stop-the-world pauses); root RC objects are explicitly defined and merged once (no need for stack scanning of threads); multithreaded deletion during iteration is avoided (there's no global sweep phase); mutators freely read data; any thread can trigger garbage collection as needed (without a dedicated GC thread).

YRC utilizes complete incRef/decRef event information, which traditional tracing garbage collectors discard and are then forced to restore through stack scanning and graph traversal. The implementation consists of only 550 lines of code and has formal verification of safety and deadlock freedom through specifications in TLA+ and proof in the Lean toolkit. YRC is positioned as "almost the last cycle collector based on reference counting" (the letter Y precedes Z in the alphabet), and also as the simplest thread-safe garbage collector — according to the author, it requires none of the complex mechanisms characteristic of traditional tracing garbage collectors.

YRC pakub sarnast API nagu ORC, kus purustajad executeerivad prĂŒgi kogumise ajal. Koguja töötleb ainult neid objekti alagrafikesi, millega lĂ”imed tegelevad, jĂ€ttes puutumata mitteseotud andmestruktuurid (vahemĂ€lu, pikaajalised objektid) — lĂ€henemine, mis sarnaneb „ideaalse“ generatiivse prĂŒgi kogumisega ilma pĂ”lvkondade kasutamiseta. Peamine puudus on jĂ”udlus: YRC nĂ€itab sooritusvĂ”imes 1,5-2,0 korda aeglasemat jĂ”udlust vĂ”rreldes ORC-iga orcbench'i soorituskatsetes. Autor peab seda tĂ€ieliku lĂ”imeohutu töötlemise jaoks ringilised viidete korral aktsepteeritavaks hinnaks.

YRC on juba saadaval Nim arendustöös ja seda aktiveeritakse lipuga "—mm:yrc". Kuid hilisemates teadetes tunnustas autor, et algne teostus sisaldas tĂ”siseid vigu ja ei kogunud tsĂŒkleid korrektselt. Artikli avaldamise hetkel on valmis komplekt parandusi, mis likvideerivad peamised vead. Autor jĂ€tkab kogumise heuristikate seadistamist ja jÀÀnud vigade parandamist, samal ajal kui pĂ”hialgoritm ja selle formaalne tĂ”estamine jÀÀvad korrektseks.

Allikas: opennet.ru

Osta usaldusvÀÀrne hostimine veebilehtede jaoks DDoS-i kaitsega, VPS VDS serverid đŸ”„ Osta usaldusvÀÀrne hostimine veebilehtede jaoks DDoS-i kaitsega, VPS VDS serverid | ProHoster