Previous | Next --- Slide 18 of 66
Back to Lecture Thumbnails
gohan2021

I didn't want to spoil the answer, but here is my solution:

init(): set EAX to 1, and x = 0.

lock(): while(compare_and_exchange(x, 1) == 1) { // spin }

unlock(): set x = 0.

jiaju

This looks exactly like atomicCAS from later in the slides. I've never worked with flags before in c level code, so how would a programmer go about using this function or what c functions interface with this x86 function?

gsamp

@gohan2021, assuming 1 signals the lock is locked and 0 signals it's unlocked, why would the initial state be locked?

Please log in to leave a comment.