develooper Front page | perl.perl5.porters | Postings from April 2006

thread non-safety in sv_setsv

Thread Next
From:
Nicholas Clark
Date:
April 1, 2006 03:55
Subject:
thread non-safety in sv_setsv
Message ID:
20060401115522.GK32132@plum.flirble.org
I've realised that there's the potential for some nasty thread unsafe code
in sv_setsv_flags, which seems to (mostly) sink any simple (read fast)
copy-on-write scheme.

The problem is that currently it's possible to quite legitimate pointer to
a (read only) SV in a parent thread, which you then pass to sv_setsv_flags to
copy *from*. sv_setsv_flags currently assumes that source and destination
are in the current interpreter, and is already doing copy-on-write of
shared hash key scalars:

    SvPV_set(dstr,
             HEK_KEY(share_hek_hek(SvSHARED_HEK_FROM_PV(SvPVX_const(sstr)))));


So currently, if you happen to pass in a pointer to a shared hash key scalar
that lives in another thread, then manipulations will be made on data
structures that belong to *that* thread without any mutex protection, rather
than a clean copy made. I think that this only gets worse with any full
copy-on-write scheme, and also means that even the current code (in blead
only) isn't thread safe.

I'm not sure if there is a solution to this.

Nicholas Clark


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About