Re: XS: MY_CXT vs PL_modglobal?

[email protected] (Shmuel Fomberg) Sun, 02 Nov 2008 00:26:54 +0200
Newsgroups perl.ithreads
Message-ID <[email protected]>
Dave Mitchell wrote:
>> A question about threads from the XS-embedding-module perspective:
>> What is the difference between MY_CXT and PL_modglobal?
> 
> PL_modglobal is a general perl-interpreter hash.

So, if a interpreter creates new threads, every thread get its own copy 
of PL_modglobal?

>> 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.

To hide the pointer inside a global (our) variable? And let the Perl 
name space be my storage. nice.

>> 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.

There is a C program (STAF) that runs a multiple Perl interpreters, each 
spanning multiple threads, and each thread is calling a certain XS 
function.
The C program needs to supply context to the XS function, so for every 
Perl that is creates it malloc a certain structure, and store the 
pointer inside PL_modglobal.

Shmuel.