Dear Paul, Paul Richard Thomas wrote: > I have checked out the code for any obvious style or other minor > errors and all looks well. However, I had a look at 8.5.6 "LOCK and > UNLOCK statements" in the standard and can only confess to feeling > very stupid tonight because I could not make head nor tail of the > example. Thus, I can offer no judgement on the functionality of your > patch. Well, for a single image - and more the current patch does not support - it is very simple: LOCK and UNLOCK do not do anything. If there is a STAT=, it is set to 0 and if there is a LOCK_ACQUIRED= it is set to true. But in general, a LOCK/UNLOCK pair allows to create a critical section, where only one process at a time processes a certain block. Mostly one image (process) can hold a lock at any given time. The simplest case for LOCK is a CRITICAL block where only one process (image) at a time can execute code in the block. However, LOCK allows more: * With LOCK_ACQUIRED, it allows to perform some alternative action when it cannot get the lock (otherwise, LOCK waits until it can obtain the lock) * As the example in the standard shows: One can use one lock (variable) to lock different section of the code. In the example (Example 8.45): Each image (process) has a work queue. This queue is filled (remotely) by its neighbour, i.e. "this_image()-1", which is possible as the work queue is a coarray. In the first block, each process checks whether there is a new item in its own ("this_image()") workqueue - in the second block, it adds a new item to the neighbouring queue. While an item is being added or removed from the queue, no parallel access should be happen - thus the access is guarded via a lock. The lock is also a coarray, thus, there are num_image() locks. In the example "work_queue" is the local arrays and thus semantically identical to "work_queue[this_image()]" while "work_queue[me+1]" refers to the remote coarray on image "me+1". > OK for trunk Thanks for the review! And good that you asked about the trans part. There was actually a bug in it: + if (stat != NULL_TREE) + gfc_add_modify (&se.pre, lock_acquired, + build_int_cst (TREE_TYPE (lock_acquired), 0)); The check in "if" should be "lock_acquired" not "stat". Corrected in the committed version (Rev. 175228). I have now also added a run-test (cf. attachment) to make sure that it actually works. > PS Please give me a co-array tutorial sometime! I will, though I think for the real fun, one needs to have a working mult-image support. Tobias