Possible to pass a member function to spawn?

Artur Skawina art.08.09 at gmail.com
Tue Feb 7 17:23:28 PST 2012


On 02/08/12 01:41, Sean Kelly wrote:
> On Feb 7, 2012, at 3:55 PM, Artur Skawina wrote:
> 
>> On 02/08/12 00:32, Sean Kelly wrote:
>>> [...] the transitivity of shared can still make for some weirdness at the implementation level.  For example, if I have:
>>>
>>> class Thread {
>>>    pthread_t p;
>>>    shared void detach() {
>>>        pthread_detach(p);
>>>    }
>>> }
>>>
>>> Building this yields:
>>>
>>> Error: function core.sys.posix.pthread.pthread_detach (_opaque_pthread_t*) is not callable using argument types (shared(_opaque_pthread_t*))
>>> Error: cannot implicitly convert expression (this.p) of type shared(_opaque_pthread_t*) to _opaque_pthread_t*
>>>
>>> So I either need to speculatively update a bunch of system API calls to add a 'shared' qualifier to everything I think will always be used in a shared context, or explicitly cast away shared when actually passing these variables to their associated API routines.  Neither option is appealing, so again I haven't done anything regarding shared.
>>
>> An overload would work, right?
>>
>> class Thread {
>>    pthread_t p;
>>    shared void detach() {
>>        pthread_detach(p);
>>    }
>>    void detach() {
>>        pthread_detach(p);
>>    }
>> }
> 
> The shared call still won't work because pthread_detach accepts a pthread_t, not a shared(pthread_t).  It might work if pthread_t weren't a pointer type, but that obviously can't be safely assumed. 

Hmm, but shouldn't the lower level thread functions use 'shared' too?
"int pthread_mutex_lock(pthread_mutex_t*);" doesn't really make sense...

artur


More information about the Digitalmars-d mailing list