On 13.11.2010 14:11, Russel Winder wrote:
On Sat, 2010-11-13 at 12:49 +0300, Dmitry Olshansky wrote:
[ . . . ]
Well at least the Thread starts )
Indeed :-)

I'd search for the clues by replacing all complicated logic with
writeln("Func x executed"); where x identifies functions.
If it prints all successfully, then it's bug in your code.
My best guess - you are not aware of "Thread-local by default", i.e. any
thread you spawn won't have access to parent's thread global data.
Anyway, I'd suggest posting it on D.learn with full source code, guys
there are quite helpful.
Using gdb I get:

         (gdb) bt
         #0  0x0804ee1a in _d_monitorenter ()
         #1  0x080498c2 in pi_d2_threads.partialSum 
(delta=9.9999999999999999998051260704522807e-10, end=4294967296, 
start=1000000001) at pi_d2_threads.d:25
Strange values you have in there :) Is it intended? Again consider providing the full code of failing example.
         #2  0x08049ae5 in pi_d2_threads.execute.__dgliteral1 (this=0xf7d24ce0) 
at pi_d2_threads.d:35
         #3  0x0804f942 in core.thread.Thread.run() ()
         #4  0x08055e3e in thread_entryPoint ()
         #5  0xf7fa7cb2 in start_thread (arg=0xf7d1fb70) at 
pthread_create..c:304
         #6  0xf7ef107e in clone () at 
../sysdeps/unix/sysv/linux/i386/clone..S:130
         (gdb)
OK, so now I know I am trying to do things the wrong way, explicit
threads, shared global data, and synchronized statements, but that is
the whole point of my examples.  Segementation fault is not though the
error message I think this should result in.
Unchecked null pointer still causes segfault, and you could easily code yourself into one when you are not aware of this default. If you are porting some existing code that expects global sharing, then I may also suggest using __gshared attribute instead of shared on all globals, and see how that swims.
Anyway I have global
objects:

         shared real sum ;
         shared Object sumMutex ;

then in the function partialSum that is being executed by each of the
threads:

         synchronized ( sumMutex ) { sum += localSum ; }

It compiles, it executes, it seg faults.



--
Dmitry Olshansky

Reply via email to