Mailinglist Archive: yast-devel (77 mails)

< Previous Next >
Re: [yast-devel] Re: [yast-commit] <rest-service> backgroud_patches_bnc550934 : patches and status - moved the shared background code
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Wed, 16 Dec 2009 10:10:49 +0100
  • Message-id: <200912161010.49607.jreidinger@xxxxxxx>
Josef Reidinger write:
Ladislav Slezak write:
+
+ # get the current progress
+ # returns a copy, use update_progress() for updating the progress
+ def get_progress(id)
+ @@mutex.synchronize do
+ ret = @@running[id]
+ ret.nil? ? nil : ret.dup

^^^
This return excepted value if you not make critical mistake ( because it
return nil, if you unlock mutex on which you invoke synchronize method. So I
recommend checking return value of synchronize to detect locking problem (but
you must change inside block to not return nil in any case).
so something like :
ret = nil
mret = @@mutex.synchronize do
ret = @@running[id]
ret = ret.dup unless ret.nil?
"OK"
done
raise "Someone unlock mutex during executing synchronize" unless mret
return ret

working in threads and locking need special care and study how it really
work, otherwise some really ugly problem can raise.


Another fix my answer. It is not neccessary and it really works as you write
it, because ensure has interesting behavior that it is not counted as last
statement.
from irb:
begin "a" ensure "b" end
=> "a"

so if synchronize call
lock
begin
yield
ensure
unlock
end
it returns value from yield.
So also another methods should be fixed just be removing 'return'.

Josef

--
Josef Reidinger
YaST team
maintainer of perl-Bootloader, YaST2-Repair, webyast
(language,time,basesystem,ntp)
--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
References