Thread overview | ||||||
---|---|---|---|---|---|---|
|
July 19, 2006 delegates and threads | ||||
---|---|---|---|---|
| ||||
Attachments: | I have been writing a function that takes an array of delegates and executes them in parallel. (attached) It works sort of but I ran into problems when I tried to use delegates that referenced the frame/this pointer. (gdc-0.18 osx based on dmd 0.157) Object a=new Object(); void foo(){printf("p");}//OK void foo(){printf("%*s",a.toString());}//segfault Is their anything in the language that prevents a thread from reading the stack of another through a pointer? (or is this a language/compiler bug) I have written a reduced test case bellow. Thanks in advance. //begin testcase import parallel; class A { void b(){printf("boo\n");} } void main() { A a=new A(); void delegate()[] o; o~=delegate void() { printf("minsk\n"); }; o~=delegate void() { a.b(); }; o~=delegate void() { printf("foo\n"); }; printf("before\n"); parallelize(o); printf("after\n"); } //prints Starting program: /Users/johan/Desktop/test/test Reading symbols for shared libraries . done before minsk foo Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_PROTECTION_FAILURE at address: 0x00000000 [Switching to process 3902 thread 0xf03] _Dmain12__dgliteral2FZv () at test.d:17 17 a.b(); //end |
July 20, 2006 Re: delegates and threads | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johan Granberg | In article <e9mc1n$8om$1@digitaldaemon.com>, Johan Granberg says... > >void foo(){printf("%*s",a.toString());}//segfault Just shooing from the hip, but you might want to try %.*s to print char[] (or just use writefln() instead). ;) - EricAnderton at yahoo |
July 20, 2006 Re: delegates and threads | ||||
---|---|---|---|---|
| ||||
Posted in reply to pragma | pragma wrote:
> In article <e9mc1n$8om$1@digitaldaemon.com>, Johan Granberg says...
>> void foo(){printf("%*s",a.toString());}//segfault
>
> Just shooing from the hip, but you might want to try %.*s to print char[] (or
> just use writefln() instead). ;)
>
> - EricAnderton at yahoo
No it is not this that is the problem. This was just a test case. The problem is that the program segfaults when dereferencing the context pointer which for some reason is null. It happens both when it points to a stack frame and when it points to a class. (it the format string was the problem it would segfault in strlen instead by the way)
|
July 22, 2006 Re: delegates and threads | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johan Granberg | On 2006-07-20 00:41:20 -0700, Johan Granberg <lijat.meREM@OVEgmail.com> said:
> pragma wrote:
>> In article <e9mc1n$8om$1@digitaldaemon.com>, Johan Granberg says...
>>> void foo(){printf("%*s",a.toString());}//segfault
>>
>> Just shooing from the hip, but you might want to try %.*s to print char[] (or
>> just use writefln() instead). ;)
>>
>> - EricAnderton at yahoo
>
> No it is not this that is the problem. This was just a test case. The problem is that the program segfaults when dereferencing the context pointer which for some reason is null. It happens both when it points to a stack frame and when it points to a class. (it the format string was the problem it would segfault in strlen instead by the way)
Did you figure out the answer to your problem?
It may be an issue with mach threads.
|
Copyright © 1999-2021 by the D Language Foundation