digitalmars.D - delegates and threads
- Johan Granberg (49/49) Jul 19 2006 I have been writing a function that takes an array of delegates and
- pragma (4/5) Jul 19 2006 Just shooing from the hip, but you might want to try %.*s to print char[...
- Johan Granberg (6/13) Jul 20 2006 No it is not this that is the problem. This was just a test case. The
- S. Chancellor (3/17) Jul 22 2006 Did you figure out the answer to your problem?
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
Jul 19 2006
In article <e9mc1n$8om$1 digitaldaemon.com>, Johan Granberg says...void foo(){printf("%*s",a.toString());}//segfaultJust shooing from the hip, but you might want to try %.*s to print char[] (or just use writefln() instead). ;) - EricAnderton at yahoo
Jul 19 2006
pragma wrote:In article <e9mc1n$8om$1 digitaldaemon.com>, Johan Granberg says...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)void foo(){printf("%*s",a.toString());}//segfaultJust shooing from the hip, but you might want to try %.*s to print char[] (or just use writefln() instead). ;) - EricAnderton at yahoo
Jul 20 2006
On 2006-07-20 00:41:20 -0700, Johan Granberg <lijat.meREM OVEgmail.com> said:pragma wrote:Did you figure out the answer to your problem? It may be an issue with mach threads.In article <e9mc1n$8om$1 digitaldaemon.com>, Johan Granberg says...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)void foo(){printf("%*s",a.toString());}//segfaultJust shooing from the hip, but you might want to try %.*s to print char[] (or just use writefln() instead). ;) - EricAnderton at yahoo
Jul 22 2006