Skip to content

Instantly share code, notes, and snippets.

@jki127
Last active November 7, 2018 18:17
Show Gist options
  • Save jki127/2ecbc09816e5a4b3d4739bec86556dcd to your computer and use it in GitHub Desktop.
Save jki127/2ecbc09816e5a4b3d4739bec86556dcd to your computer and use it in GitHub Desktop.

Some Midterm Solutions - DistSys Lecture - Nov 6th, 2018 (Part 1)

Spinlock

func (s *Spinlock) Lock() {
	for {
		test := 0
		Cmpxchg(&test, &s.held, 1)
		if test == 0 {
			break
		}
	}
}

func (s *Spinlock) Unlock() {
	// You don't need to use Cmpxchg here because
	// only one thread should have ownership of the
	// lock
	s.held = 0
}

Question 6

Since RPCs go across systems, we want to send the value that the pointer is pointing to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment