Table of Contents
- Syscalls, memory, and your first therad
 - The pointer to self and thread-local storage
 - Futexes, mutexes, and memory sychronization
 - Joining threads and dynamic initialization
 - Cancellation
 - Scheduling and task priority
 - RW Locks
 - Condition variables
 - Final thoughts
 
Conclusion
I have implemented all of the interesting functions listed here and, thus, reached my goal. There were quite a few surprises. I had expected some things to bo more complicated than they are. Conversely, some things that had seemed simple turned out to be quite complex.
- I had initially hoped that I would be able to re-use much of glibc and concentrate only on the thread-specific functionality. I was surprised to discover how much of glibc code refers to thread-local storage.
 - I had expected the interaction between 
joinanddetachto be much simpler to handle. Having to implement descriptor caching was an unexpected event. - I had never heard of 
pthread_oncebefore. - I had not used much of the real-time functionality before, so figuring out the scheduling part was very entertaining. I especially enjoyed implementing the PRIO_INHERIT mutex.
 
I may revisit this project in the future because there are still some things that I would like to learn more about.
- If I'll have the time to learn DWARF, I would like to provide proper
.eh_framefor the signal trampoline. It would allow me to implement cancellation using stack unwinding the way glibc does it. - I may look into the inter-process synchronization to learn about the robust futexes.
 - The Intel article on lock elision seemed interesting, and I'd like to play with this stuff as well.
 - I may have a look at the compiler-generated TLS.
 
The End
If you like this kind of content, you can subscribe to my newsletter, follow me on Twitter, or subscribe to my RSS channel.