develooper Front page | perl.ithreads | Postings from October 2008

Re: XS: MY_CXT vs PL_modglobal?

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
October 31, 2008 20:04
Subject:
Re: XS: MY_CXT vs PL_modglobal?
Message ID:
20081031180440.GE3809@iabyn.com
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

Thread Previous | 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