digitalmars.D.learn - Using map to create a sequence
- Russel Winder (41/41) Aug 04 2012 auto a =3D map!((a)=3D>2*a)(iota(10));
auto a =3D map!((a)=3D>2*a)(iota(10));
Appears to do exactly what is says on the can. However, whilst:
auto threads =3D new Thread [ numberOfThreads ] ; =20
foreach ( i ; 0 .. numberOfThreads ) {
auto closedPartialSum ( ) {
immutable ii =3D i ;
return delegate ( ) { partialSum ( ii , sliceSize , delta ) ; } ;
}
threads[i] =3D new Thread ( closedPartialSum ) ;
}
foreach ( thread ; threads ) { thread.start ( ) ; }
works fine:
auto threads =3D map ! ( ( int i ) {
auto closedPartialSum ( ) {
immutable ii =3D 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=3D0x7ffff7ed1fe0) 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.
--=20
Russel.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n=
et
41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Aug 04 2012








Russel Winder <russel winder.org.uk>