On Fri, Sep 4, 2009 at 12:11 AM, Bakul Shah <bakul+plan9@bitblocks.com> wrote:
On Thu, 03 Sep 2009 22:35:35 PDT David Leimbach <leimy2k@gmail.com>  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), <uninitialized>,
>       __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