Hi
This is quite tricky indeed.
There are subtle differences between the `when' construct and your proposed
expansion.
Before I get into particulars, let me first say I don't understand the
comment
> // wait for some atomic to finish //
so I may not fully understand the intend here.
I see two main issues with the expansion.
1.
`when' blocks until a point in the execution is reached where`G' is true.
You proposed expansion keeps checking the condition `G'.
So while the implementation of `when' may do the same, it can also rely
notification mechanisms more efficient than spin loops.
2.
The X10 scheduler is a cooperative one.
The `when' construct suspends the execution freeing resources (think CPU or
thread) for other activities to use.
In the proposed loop, the activity never stops, therefore will never be
preempted by the X10 runtime.
While there may be a runnable activity willing to update `G', it is
unlikely but entirely possible that this activity will never run, which
would result in a deadlock.
Now getting back to the comment in the code, there is no way to wait for
another atomic to finish
without again using when or atomic in a loop.
I hope this helps.
Olivier
Andreas Zwinkau <zwin...@kit.edu> wrote on 06/14/2012 02:48:50 AM:
> From: Andreas Zwinkau <zwin...@kit.edu>
> To: x10-users@lists.sourceforge.net,
> Date: 06/14/2012 02:49 AM
> Subject: [X10-users] when semantics
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> The X10 spec provides two examples, how 'when' cannot be implemented
> with 'if' and 'atomic'. However, an additional loop seems to do the
trick:
>
> when (G) S;
>
> ==into==>
>
> while (true) {
> atomic {
> if (G) {
> S;
> break;
> }
> }
> // wait for some atomic to finish //
> }
>
> For my simple test, it seems to work, but concurrency is tricky. ;)
>
> - --
> Andreas Zwinkau
>
> Karlsruhe Institute of Technology (KIT)
> Institut für Programmstrukturen und Datenorganisation (IPD)
> Lehrstuhl Prof. Snelting
> Adenauerring 20a
> 76131 Karlsruhe
>
> Phone: +49 721 608 48351
> Fax: +49 721 608 48457
> Email: zwin...@kit.edu
> Web: http://pp.info.uni-karlsruhe.de/person.php?id=107
>
> KIT – University of the State of Baden-Wuerttemberg and
> National Research Center of the Helmholtz Association
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iQEcBAEBAgAGBQJP2YlSAAoJEKm3M8a3pi2i24MH/2lhvl3V5nYmREh2MK5fQPHj
> iM6Me+lGqfL7V3qXP4aN9rkazQXnf/agbjMu/x9hCMoS5E/gj45KfCal2+23YsYN
> eoaU5QZnJNvEYMb93hbaHA4XRg0FjIaTBT/PpiIezjD1EcG7bWPWzdlgyQGDP/9Z
> UfdQngWiblOYOZb97sW0/XMu87R0isxg1PVdaWh0bPbbPTgrYDeqcL+nwXVTOSI3
> bxXAogYU31a+TQCjIxseqObZgSX+mTcNoeN9Gs0b1isOt059cdNnmizzvGIwlW/y
> 8Q0NfbpuhAzDQD9HaPlYetVjaeARO9peEcO4LJ4oTBTWxgTtGrzg5yJGUFUBKYw=
> =meq/
> -----END PGP SIGNATURE-----
>
>
------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> X10-users mailing list
> X10-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/x10-users
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users