Created
January 2, 2010 00:19
-
-
Save andymatuschak/267316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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