-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 25.06.2012 16:59, Olivier Tardieu wrote: > 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 > > > 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. ;)
So I understand that my expansion is *semantically* equivalent if we assume at least a parallelism of two to rule out the deadlock situation you describe. In terms of efficiency/performance 'when' should be superior, since it can "wait for some atomic to finish". This could be understood as an optimization. On the other hand, there seems to be a way to wait for another atomic to finish with a simple call: "x10.lang.Runtime.awaitAtomic();". At least, that seems to be what the runtime does. - -- 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/ iQEcBAEBAgAGBQJP6WlGAAoJEKm3M8a3pi2iYDIH/AjProM28IuqSqwYGLNgbbwr WVwCSVqpBxQFOdaRmv/Q5hPmQPxmGwyzZNdsN+LdQTBsqWtG/AMNLt0GPD5CWRA8 aZP7UB8EiIhBYOKJ/aIoitidRf0VxKxY0VyarX8K9I1g6x6DlI59IJd+vY6xaPB7 gWecp/1Bzm2dvS+DVLR8oawH54clJ4HT9u0uaVdYHhlxLVCagfMZUUAAxTgRAJQv tHGyXY7guKSAgxrUPZVi1UXGECbDVFkeW3agakcvhAGOrV3wflej+xTYcbZkuzGS 8ngYlL2ThIFTEZZ1YcU6KN3/jLanmRVYSif8iHdJlo6sXlU/yng+kcu5sfm2Sik= =8IUp -----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