Forklang supports the locking and unlocking of locks to synchronize accesses (read and write) to memory. Languages
Question:
Forklang supports the locking and unlocking of locks to synchronize accesses (read and write) to memory.
Languages like Java provide higher-level synchronization mechanisms such as synchronized methods or blocks. A synchronized method of an object locks the object at the beginning of the execution of the method and unlocks it before returning from the method.
Similarly, a synchronized block locks the object upon entering the block and unlocks it when exiting the block.
Extend Forklang with a synchronized expression.
The syntax of a synchronized expression follows the following grammar:
Semantically, a synchronized expression (synchronized exp1 exp2) treats exp1 as a lock. Similar to the lock expression, it evaluates exp1 to a location and acquires the lock. Then the synchronization expression evaluates exp2 while the lock is acquired. And finally, the lock is released when the evaluation of exp2 is done.
The following interaction log illustrates the semantics of synchronized expression:
Step by Step Answer:
An Experiential Introduction To Principles Of Programming Languages
ISBN: 9780262045452
1st Edition
Authors: Hridesh Rajan