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:image

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:image

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: