From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <20090904071109.11C405B18@mail.bitblocks.com> References: <3e1162e60909032118h60620d2cj74791672e5f55a5f@mail.gmail.com> <0084d6ddb9d674fa38925596dabc8d78@quanstro.net> <3e1162e60909032231h5a2cc329x89744a497052e551@mail.gmail.com> <3e1162e60909032235s6e5a67dau6109f30246f255d@mail.gmail.com> <20090904071109.11C405B18@mail.bitblocks.com> Date: Fri, 4 Sep 2009 00:47:18 -0700 Message-ID: <3e1162e60909040047q2f3451e4k2880720beb2a1373@mail.gmail.com> From: David Leimbach To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=000e0cd353e89d23dd0472bbb5e4 Subject: Re: [9fans] "Blocks" in C Topicbox-Message-UUID: 63ca8726-ead5-11e9-9d60-3106f5b1d025 --000e0cd353e89d23dd0472bbb5e4 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Sep 4, 2009 at 12:11 AM, Bakul Shah > wrote: > On Thu, 03 Sep 2009 22:35:35 PDT David Leimbach > wrote: > > > > > > Actually, reading on a bit more they deal with the "variable capture" > > talking about const copies. > > > > Automatic storage variables not marked with __block are imported as > > const copies. > > > > The simplest example is that of importing a variable of type int. > > > > int x = 10; > > void (^vv)(void) = ^{ printf("x is %d\n", x); } > > x = 11; > > vv(); > > > > would be compiled > > > > struct __block_literal_2 { > > void *isa; > > int flags; > > int reserved; > > void (*invoke)(struct __block_literal_2 *); > > struct __block_descriptor_2 *descriptor; > > const int x; > > }; > > > > void __block_invoke_2(struct __block_literal_2 *_block) { > > printf("x is %d\n", _block->x); > > } > > > > static struct __block_descriptor_2 { > > unsigned long int reserved; > > unsigned long int Block_size; > > } __block_descriptor_2 = { 0, sizeof(struct __block_literal_2) }; > > > > and > > > > struct __block_literal_2 __block_literal_2 = { > > &_NSConcreteStackBlock, > > (1<<29), , > > __block_invoke_2, > > &__block_descriptor_2, > > x > > }; > > > > In summary, scalars, structures, unions, and function pointers are > > generally imported as const copies with no need for helper functions. > > Just read this after posting my last message. > > But this has no more to do with parallelism than any other > feature of C. If you used __block vars in a block, you'd > still need to lock them when the block is called from > different threads. > > I just wrote a prime sieve with terrible shutdown synchronization you can look at here: http://paste.lisp.org/display/86549 Dave --000e0cd353e89d23dd0472bbb5e4 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Fri, Sep 4, 2009 at 12:11 AM, Bakul S= hah <ba= kul+plan9@bitblocks.com> wrote:
On Thu, 03 Sep 2009 22:35:35 PDT David Le= imbach <leimy2k@gmail.com> = =A0wrote:
>
>
> Actually, reading on a bit more they deal with the "variable capt= ure"
> talking about const copies.
>
> Automatic storage variables not marked with __block are imported as > const copies.
>
> The simplest example is that of importing a variable of type int.
>
> =A0 =A0int x =3D 10;
> =A0 =A0void (^vv)(void) =3D ^{ printf("x is %d\n", x); }
> =A0 =A0x =3D 11;
> =A0 =A0vv();
>
> would be compiled
>
> struct __block_literal_2 {
> =A0 =A0 void *isa;
> =A0 =A0 int flags;
> =A0 =A0 int reserved;
> =A0 =A0 void (*invoke)(struct __block_literal_2 *);
> =A0 =A0 struct __block_descriptor_2 *descriptor;
> =A0 =A0 const int x;
> };
>
> void __block_invoke_2(struct __block_literal_2 *_block) {
> =A0 =A0 printf("x is %d\n", _block->x);
> }
>
> static struct __block_descriptor_2 {
> =A0 =A0 unsigned long int reserved;
> =A0 =A0 unsigned long int Block_size;
> } __block_descriptor_2 =3D { 0, sizeof(struct __block_literal_2) }; >
> and
>
> =A0 struct __block_literal_2 __block_literal_2 =3D {
> =A0 =A0 =A0 &_NSConcreteStackBlock,
> =A0 =A0 =A0 (1<<29), <uninitialized>,
> =A0 =A0 =A0 __block_invoke_2,
> =A0 =A0 =A0 &__block_descriptor_2,
> =A0 =A0 =A0 =A0 x
> =A0 =A0};
>
> In summary, scalars, structures, unions, and function pointers are
> generally imported as const copies with no need for helper functions.<= br>
Just read this after posting my last message.

But this has no more to do with parallelism than any other
feature of C. If you used __block vars in a block, you'd
still need to lock them when the block is called from
different threads.


I just wrote a prime sieve with terrib= le shutdown synchronization you can look at here:


Dave=A0

--000e0cd353e89d23dd0472bbb5e4--