Hi Eric,

No, there isn't something similar. The overhead of this would actually be non 
trivial in Rubinius, since we have actual concurrent threads, so an 
implementation similar to MRI will suffer from all kinds of race conditions in 
Rubinius. There is no guarantee whatsoever, that when reading the locked 
variable, it will still be there then when actually reading / writing 
something. So the only solution is to actually lock the entire string for every 
modifying operation.

This would also be necessary for every operation that happens when the string 
is not "locked", so it would mean a general performance impact for all string 
operations. This is necessary so no locking happens while another thread is 
modifying something, a problem MRI does not have because of the GIL. We don't 
want to add synchronization across every string operation, so there is nothing 
that works like this and probably never will be.

How is the string shared for this problem? If it's some output string you 
share, the only way to do it is to lock it. In Rubinius you can actually use 
every object as a lock, much like in Java:

Rubinius.synchronize(string) do

end

This functionality is not (yet) exposed to the C-API, but it might be an idea 
to expose it there too for extensions to use then. 

-- 
Dirkjan Bussink

On Apr 5, 2013, at 5:00 , Eric Wong <[email protected]> wrote:

> Hi all, MRI has rb_str_locktmp/rb_str_unlocktmp functions for preventing
> several threads from writing to the same string.  io.c in the MRI source
> has examples of its use.
> 
> Is there something similar in Rubinius?
> 
> If not, I will probably hash the VALUE to a fixed set of mutexes (maybe
> #locks will be scaled to processor count) and use pthread_mutex_trylock
> to emulate that behavior...
> 
> -- 
> -- 
> --- !ruby/object:MailingList
> name: rubinius-dev
> view: http://groups.google.com/group/rubinius-dev?hl=en
> post: [email protected]
> unsubscribe: [email protected]
> --- 
> You received this message because you are subscribed to the Google Groups 
> "rubinius-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
-- 
--- !ruby/object:MailingList
name: rubinius-dev
view: http://groups.google.com/group/rubinius-dev?hl=en
post: [email protected]
unsubscribe: [email protected]
--- 
You received this message because you are subscribed to the Google Groups 
"rubinius-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to