All pastes #385118 Raw Edit

Untitled

public text v1 · immutable
·published 2007-03-07 16:41 UTC
rendered paste body
class Semaphore():


	def __init__(self,startingCount):
		count = startingCount

	def down():
		while count <= 0:
			# We must wait
			self.waitUntilRunning.wait()
			count=count-1


	def up():
		count=count+1
		# notify a waiting thread to wakeup
		if count == 1 :
			self.waitUntilRunning.notify()





class Philosopher (Thread):
	s=Semaphore[N]