What is shared functions?

Steven Schveighoffer schveiguy at yahoo.com
Mon Oct 24 08:23:54 PDT 2011


On Sun, 23 Oct 2011 08:32:34 -0400, simendsjo <simendsjo at gmail.com> wrote:

> What does shared for functions mean? I thought it was supposed to  
> automatically synchronize access, but this doesn't seem to be the case.
>
> void f() shared {
> // no synchronization
> }
>
> void f() {
>    synchronized {
>      // do stuff
>    }
> }

Shared functions do not affect the function.  All they do is affect the  
'this' pointer.

This:

struct S
{
     void f() shared {}
}

is roughly equivalent to this:

struct S
{}

void f(shared ref Foo this){}

-Steve


More information about the Digitalmars-d-learn mailing list