Using map to create a sequence
Russel Winder
russel at winder.org.uk
Sat Aug 4 08:54:03 PDT 2012
auto a = map!((a)=>2*a)(iota(10));
Appears to do exactly what is says on the can. However, whilst:
auto threads = new Thread [ numberOfThreads ] ;
foreach ( i ; 0 .. numberOfThreads ) {
auto closedPartialSum ( ) {
immutable ii = i ;
return delegate ( ) { partialSum ( ii , sliceSize , delta ) ; } ;
}
threads[i] = new Thread ( closedPartialSum ) ;
}
foreach ( thread ; threads ) { thread.start ( ) ; }
works fine:
auto threads = map ! ( ( int i ) {
auto closedPartialSum ( ) {
immutable ii = i ;
return delegate ( ) { partialSum ( ii , sliceSize , delta
) ; } ;
}
return new Thread ( closedPartialSum ) ;
} ) ( iota ( numberOfThreads ) ) ;
foreach ( thread ; threads ) { thread.start ( ) ; }
causes a SIGSEGV:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff73af700 (LWP 8840)]
0x000000000044f8a5 in
pi_d_threadsGlobalState_array_declarative.execute()
(this=0x7ffff7ed1fe0) at pi_d_threadsGlobalState_array_declarative.d:39
39 return delegate ( ) { partialSum ( ii , sliceSize , delta
) ; } ;
This is with dmd 2.059 and so not a 2.060 thing.
Nudges in the right direction most welcome.
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder at ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: russel at winder.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20120804/41962bce/attachment.pgp>
More information about the Digitalmars-d-learn
mailing list