Question about std.bind

Dmitry Olshansky dmitry.olsh at gmail.com
Sat Nov 13 01:49:52 PST 2010


On 13.11.2010 11:12, Russel Winder wrote:
> On Fri, 2010-11-12 at 23:14 +0300, Dmitry Olshansky wrote:
> [ . . . ]
>>> I have a thread creation loop:
>>>
>>>           foreach ( i ; 0 .. numberOfThreads ) { threads[i] = new Thread ( bind (&   partialSum , 1 + i * sliceSize , ( i + 1 ) * sliceSize , delta ) ) ; }
>>>
>> I'd try to replace bind with delegate:
>> threads[i] = new Thread( (){ return partialSum(1 + i * sliceSize, (i +
>> 1) * sliceSize, delta); } );
>>
>> I'm not sure if std.bind works now, and why we even need it in D2 since
>> it's functionality is completely superseded by delegates.
>> Well if Q was about D1...
> [ . . . ]
>
> I will certainly give using an anonymous function in this way a go, but
> if partial application is a part of the language (and I am using D
> 2.050), then it ought to work.
>
> Sadly, using an anonymous function my code compiles, but on execution
> just gives a segmentation fault.
>
>
> [Thread debugging using libthread_db enabled]
> [New Thread 0xf7d1fb70 (LWP 13922)]
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0xf7d1fb70 (LWP 13922)]
> 0x0804ee0a in _d_monitorenter ()
>
>
Well at least the Thread starts )

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.

-- 
Dmitry Olshansky



More information about the Digitalmars-d mailing list