From mboxrd@z Thu Jan 1 00:00:00 1970 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> In-reply-to: Your message of "Thu, 03 Sep 2009 22:35:35 PDT." <3e1162e60909032235s6e5a67dau6109f30246f255d@mail.gmail.com> References: <3e1162e60909032118h60620d2cj74791672e5f55a5f@mail.gmail.com> <0084d6ddb9d674fa38925596dabc8d78@quanstro.net> <3e1162e60909032231h5a2cc329x89744a497052e551@mail.gmail.com> <3e1162e60909032235s6e5a67dau6109f30246f255d@mail.gmail.com> From: Bakul Shah Date: Fri, 4 Sep 2009 00:11:08 -0700 Message-Id: <20090904071109.11C405B18@mail.bitblocks.com> Subject: Re: [9fans] "Blocks" in C Topicbox-Message-UUID: 63c33f70-ead5-11e9-9d60-3106f5b1d025 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.