This is a little snippet of code, that I've written in C and C++ before. This time it's for papyrus.
It's a ticket-based spinlock. For those with a comp-sci background, known as a ticket lock (Communicating Sequential Processes - C.A.R.Hoare, Chapter 6.6 Scheduling).
So what does it offer:
it's a spinlock (i.e. a form of mutex)
it's fair (the thread that waits the longest for the lock is the one that will acquire it next).
It provides 3 functions:
Function lock()
locks the