[#2367] Standard libraries — Dave Thomas <dave@...>

From ruby-dev summary:

60 messages 2004/02/11

[#2397] PATCH: deprecate cgi-lib, getopts, importenv, parsearg from standard library — Gavin Sinclair <gsinclair@...>

Index: cgi-lib.rb

15 messages 2004/02/12

[#2465] PATCH: OpenStruct#initialize to yield self — Gavin Sinclair <gsinclair@...>

This is a common approach I use to object initialization; I don't know

24 messages 2004/02/19

Re: rehash segfault

From: Eivind Eklund <eivind@...>
Date: 2004-02-25 11:59:56 UTC
List: ruby-core #2501
On Wed, Feb 25, 2004 at 05:44:30PM +0900, Yukihiro Matsumoto wrote:
> In message "Re: rehash segfault"
>     on 04/02/25, Eivind Eklund <eivind@FreeBSD.org> writes:
> 
> |> Ruby hashes are not completely thread-safe.  I knew the problem
> |> existed, but I couldn't fix it without significant slow-down.
> |
> |What is the exact problem that makes it hard to fix without slowdown?
> 
> Hash calls back a few Ruby methods, e.g. "hash", "eql?", etc, during
> which context switch may happen.  To avoid this, the easiest way is to
> prepare mutex for each hash and protect every hash operation, that, I
> think, cause significant slow-down.

This is a fun problem! :-)

As far as I can tell, the only "atomic"[1] ops available in the
ruby source code are the ATOMIC_ code in rubysig.h.  Is this correct?

I *think* I can do an implementation based on sequencing all rehashes,
turning rehash into an incremental operation where elements are moved
from the old to the new map, tracking active/quiscent maps, and having a
hash lookup during a rehash look into both the old and the new table.

This would give the following extra cost compared to a non-threadsafe
variant:

For read and write:
    1 ATOMIC_INC for starting
    1 ATOMIC_DEC for ending
    One extra test of a pointer variable
    During rehashing:
        Partial extra scan (need to both scan the present table and the
	table being buit)
	One extra ATOMIC_INC
	One extra ATOMIC_DEC


For rehashing:
    One mutex test (no parallell rehashing allowed)
    The extra memory for one table (but that's used in the present
       implementation anyway)
    A wait for the old map to become quiescent, which would correspond
       to the time used to do a lookup in the old table.

Would this be an acceptable extra cost?

Eivind.

[1] The present implementation is not guaranteed atomic for the
    non-Windows case, though it will probably often be atomic in
    practice.

In This Thread