Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Almost Done ... Still Stuckin' Wiith Some MSG Error while The Slave Should Recieve ...
[simgrid.git] / src / bindings / ruby / Semaphore.rb
index 8da1c42..d8697c5 100644 (file)
@@ -1,45 +1,45 @@
+# 
+#  * $Id$
+#  *
+#  * Copyright 2010 Martin Quinson, Mehdi Fekari           
+#  * All right reserved. 
+#  *
+#  * This program is free software; you can redistribute 
+#  * it and/or modify it under the terms of the license 
+#  *(GNU LGPL) which comes with this package. 
 require 'thread'
 class Semaphore
   
-  
   Thread.abort_on_exception = true
-
   attr_accessor :permits, :mutex, :cv
-  
-  
-  
+   
   def initialize ( permits )
     
-    
       @permits = permits
       @mutex = Mutex.new
       @cv = ConditionVariable.new
     
   end
-  
-  
+   
+
   def acquire()
 
     raise "Interrupted Thread " if (!Thread.current.alive?)
     @mutex.synchronize {
     while @permits < 1
-      @cv.wait(mutex)
+       @cv.wait(@mutex)
     end
     @permits = @permits - 1
     }
   end
     
-  
   def release()
     @mutex.synchronize{
-      @value = @value + 1
+      
+      @permits += 1
       @cv.signal
-         
+       
       }
-    
   end
   
-  
-
-  
 end
\ No newline at end of file