-2

I'm looking for a good online reference on typical implementation of synchronization primitives (spinlocks, mutexes, semaphores, read-write locks, conditional variables, ...) either in abstract c+atomics or pseudo-asm (i.e. any reasonable notation of the sequence of atomic operations performed) or x86 asm. Something that starts with the most naive implementations and then addresses their shortcomings and some of the approaches to solving the shortcomings would be great.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • Voting to close as resource recommendation. See also: a question that asks how: http://stackoverflow.com/questions/2368164/how-is-thread-synchronization-implemented-at-the-assembly-language-level – Ciro Santilli OurBigBook.com Jun 16 '15 at 09:54

3 Answers3

2

Try Tanenbaum's Operating Systems: Design and Implementation.

edit: or Modern Operating Systems. I think the 1st one includes Minix, the 2nd one doesn't. Not sure, sorry =(

It's academically oriented, so it'll get you started on the right path.

salezica
  • 74,081
  • 25
  • 105
  • 166
1

Not a complete reference by any means, but the following paper is a classic and essential for understanding the implementation of synchronisation primitives in Linux:

"Fuss, Futexes and Furwocks: Fast Userlevel locking in Linux", Franke Russell & Kirkwod, Proceedings of the Ottawa Linux Symposium 2002 - available (among others) at: http://www.cis.temple.edu/~ingargio/cis307/readings/futex0.pdf

From that and the glibc sources it's possible to learn a lot, but it's not what I'd call easy-going :-)

psmears
  • 26,070
  • 4
  • 40
  • 48
  • Really interesting. Not so much what I was looking for, but it's amazing how the final design of futex wasn't immediately apparent. Guess it shows how stuck in the "everything is a semaphore" mindset the kernel folks are.. ;-) – R.. GitHub STOP HELPING ICE Nov 26 '10 at 00:03
0

As a side note, if you just want atomic stuff and you'r using gcc you have some built in functions that you can use instead of asm.

http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html

But for specific locks you always have Wikipedia

http://en.wikipedia.org/wiki/Spinlock

http://en.wikipedia.org/wiki/Semaphore_(programming)

Also worth looking at is

http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms

Sven Almgren
  • 183
  • 10