Complete! I wrote my own thread implementation in C from scratch

Опубликовано: 10 Октябрь 2024
на канале: dr Jonas Birch
1,528
93

So I wrote my own Thread Implementation
...And I did it in 400 lines of code vs 30k+ lines in lib-pthread. Even so, my lib:

x Is super-easy to use, all mutex related concurrent stuff happens automatically behind the scenes.
x You declare the var x using let(x), then you read/write with macros get() and put()
x let-variables are always 64 bit in data size plus eight mutex bits
x They are allocated from an internal heap-like structure, shared between the forks/threads/needles and this data block is allocated using mmap()

The library is a combo of several techniques where the shared heap is one vital part. Credit to my dear colleague, emacs ninja and hacker [Ref 1] for his excellent walk-through of this syscall.

In this beginner-friendly episode I show how to Use the library, which is incredibly easy.

References

1.
‪@TsodingDaily‬

2.
Needlethreads library (docs and source code)
https://www.npmjs.com/package/needlet...