From b2486284a8e1ce3f9f4c0d10019ae3f8c1c414d5 Mon Sep 17 00:00:00 2001 From: coldpeace Date: Thu, 4 Mar 2010 11:05:08 +0000 Subject: [PATCH] DeadLock git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7184 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/bindings/ruby/rb_application_handler.c | 7 --- src/bindings/ruby/simgrid.rb | 58 ++++++++++++++++++---- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/bindings/ruby/rb_application_handler.c b/src/bindings/ruby/rb_application_handler.c index 97f6b8ec4b..a54d6fe873 100644 --- a/src/bindings/ruby/rb_application_handler.c +++ b/src/bindings/ruby/rb_application_handler.c @@ -16,7 +16,6 @@ static VALUE prop; static VALUE function_name; static VALUE host_name; - static VALUE rb_process_instance(VALUE fct_name,VALUE arguments,VALUE properties) { ruby_init(); ruby_init_loadpath(); @@ -37,7 +36,6 @@ static void rb_process_create_with_args(VALUE fct_name,VALUE arguments,VALUE pro // Allocate the data for the simulation process = xbt_new0(s_m_process_t,1); process->simdata = xbt_new0(s_simdata_process_t,1); - // Do we Really Need to Create Ruby Process Instance , >> process is already a Ruby Process !! So..Keep on ;) // Bind The Ruby Process instance to The Native Process rb_process_bind(ruby_process,process); name = RSTRING(fct_name)->ptr; @@ -46,8 +44,6 @@ static void rb_process_create_with_args(VALUE fct_name,VALUE arguments,VALUE pro m_host_t host = MSG_get_host_by_name(RSTRING(ht_name)->ptr); process->simdata->m_host = host; - //Data_Get_Struct(host,s_m_host_t,process->simdata->m_host); - if(!(process->simdata->m_host)) { // Not Binded free(process->simdata); free(process->data); @@ -61,7 +57,6 @@ static void rb_process_create_with_args(VALUE fct_name,VALUE arguments,VALUE pro process,process->simdata, process->simdata->m_host, process->simdata->m_host->simdata); - /* FIXME: that's mainly for debugging. We could only allocate this if XBT_LOG_ISENABLED(ruby,debug) is true since I guess this leaks */ char **argv=xbt_new(char*,2); argv[0] = bprintf("%s@%s",process->name,process->simdata->m_host->simdata->smx_host->name); @@ -86,8 +81,6 @@ static void rb_process_create_with_args(VALUE fct_name,VALUE arguments,VALUE pro } - - void rb_application_handler_on_start_document(void) { args = rb_ary_new(); // Max lenght = 16 ?! diff --git a/src/bindings/ruby/simgrid.rb b/src/bindings/ruby/simgrid.rb index 11e1e99d4d..a35501344c 100644 --- a/src/bindings/ruby/simgrid.rb +++ b/src/bindings/ruby/simgrid.rb @@ -8,6 +8,40 @@ $DEBUG = false # This is a Global Variable Useful for MSG::debugging ########################################################################### # Class Semaphore ########################################################################### +class MySemaphore + Thread.abort_on_exception = true + attr_accessor :permits + + + def initialize (permits = 0) + @permits = permits + end + + def acquire(mutex,cv) + + raise "Interrupted Thread " if (!Thread.current.alive?) + mutex.synchronize { + while @permits <= 0 + + cv.wait(mutex) + + end + @permits = @permits - 1 + cv.signal + } + + end + + def release(mutex,cv) + mutex.synchronize{ + @permits += 1 + cv.signal + } + end +end +####################################### +# Another Semaphore +####################################### class Semaphore def initialize(initvalue = 0) @@ -61,13 +95,16 @@ class MSG::Process < Thread raise "Bad Number Of arguments to create a Ruby Process (name,args,prop) " if args.size < 3 +# @cv = ConditionVariable.new +# @mutex = Mutex.new @schedBegin = Semaphore.new(0) @schedEnd = Semaphore.new(0) - #@properties = Hash.new() FIXME: get this from the C (yep that makes 4 args to this function) - @id = @@nextProcessId++ + @id = @@nextProcessId + @@nextProcessId +=1 @name = args[0] @pargs = args[1] @properties = args[2] + start() } end @@ -80,12 +117,12 @@ class MSG::Process < Thread # Start : To keep the process alive and waiting via semaphore def start() - @schedBegin.acquire + @schedBegin.acquire() # execute the main code of the process MSG::debug("Begin execution") main(@pargs) # processExit(self) # Exit the Native Process - @schedEnd.release + @schedEnd.release() end @@ -101,13 +138,13 @@ class MSG::Process < Thread end def unschedule() - @schedEnd.release - @schedBegin.acquire + @schedEnd.release() + @schedBegin.acquire() end def schedule() - @schedBegin.release - @schedEnd.acquire + @schedBegin.release() + @schedEnd.acquire() end def pause() @@ -147,11 +184,12 @@ class MSG::Task < MSG::RbTask end def send(mailbox) - super(mailbox) + super(self,mailbox) end +# FIXME : this methode should be associated to the class !! it reurn a task def receive(mailbox) - super(mailbox) + super(self,mailbox) end def source -- 2.20.1