[MacRuby-devel] [MacRuby] #477: Need GCD wrapper for dispatch_once
MacRuby
ruby-noreply at macosforge.org
Fri Dec 18 18:03:53 PST 2009
#477: Need GCD wrapper for dispatch_once
----------------------------------------+-----------------------------------
Reporter: ernest.prabhakar@… | Owner: lsansonetti@…
Type: enhancement | Status: new
Priority: minor | Milestone: MacRuby 0.5
Component: MacRuby | Keywords:
----------------------------------------+-----------------------------------
Comment(by lsansonetti@…):
The only way I see to implement this (without hacking the compiler) is to
keep a static map of dispatch_once_t structures dynamically allocated on
the fly and using the position of the caller within the stack frame as the
unique id (key). However, accessing the table in a thread-safe manner will
imply to keep it protected with a lock. I therefore wonder if all of this
is really worth doing, since a call to Dispatch.once will be costlier than
expected, and very similar to the following pure-Ruby code (which should
even run faster):
{{{
@lock = Mutex.new
..
@lock.synchronize do
@called ||= false
unless @called
do_stuff
@called = true
end
end
}}}
--
Ticket URL: <http://www.macruby.org/trac/ticket/477#comment:6>
MacRuby <http://macruby.org/>
More information about the MacRuby-devel
mailing list