On Mon, Oct 27, 2008 at 10:54:08PM +0200, Shmuel Fomberg wrote:
> A question about threads from the XS-embedding-module perspective:
> What is the difference between MY_CXT and PL_modglobal?
MY_CXT is a mechanism for providing some per-interpreter 'static' memory;
ie to replace a 'static' declaration in an XS file where each perl
interpreter would need a different one.
PL_modglobal is a general perl-interpreter hash.
Prior to 5.10, the MY_CXT mechanism used PL_modglobal to look up its
structures; now it uses a quicker, more lightweight mechanism.
> I have implemented C running Perl module that embed a C XS function, and
> want to pass a pointer to that function from the C code that runs Perl.
> The Perl side span multiple threads, and each call that C function.
The usual way of doing this is to store the pointer in an SV using using
the PTR2UV and INT2PTR macros. This may remove your need to use MY_CXT.
> Until now I used PL_modglobal, as I thought that it is per-interpreter
> hash that can be used safely from different threads. After a few
> crashes, I'm not so sure.
Neither modglobal nor MY_CXT is likely to be thread-safe in the way you
are expecting, although see MY_CXT_CLONE.
>
> So, what is the difference between MY_CXT and PL_modglobal? not in the
> global scope that one have while the other is local, but from threads
> safety question.
I'd need more details on how how your are creating and using threads and
interpreters to be able to answer that.
--
All wight. I will give you one more chance. This time, I want to hear
no Wubens. No Weginalds. No Wudolf the wed-nosed weindeers.
-- Life of Brian