Skip to content

Instantly share code, notes, and snippets.

@andymatuschak
Created January 2, 2010 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymatuschak/267316 to your computer and use it in GitHub Desktop.
Save andymatuschak/267316 to your computer and use it in GitHub Desktop.
# What's wrong with List's "insert" method if called from multiple threads?
# How would you fix it?
class Node:
def __init__(self, value):
self.value = value
self.next = None
class List:
def __init__(self):
self.head = None
def insert(self, value):
new_node = self.Node(value)
if (self.head == None):
self.head = new_node
else:
current = self.head
while (current.next != None):
current = current.next
current.next = new_node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment