The following problems relate to data races in Forklang programs. 1. Write a Forklang function that creates

Question:

The following problems relate to data races in Forklang programs.

1. Write a Forklang function that creates a location in the heap, stores an empty list at that location, and assigns the name “buffer.”
Following this, the program forks two concurrent tasks: the first task replaces the value stored at the location “buffer” with a list containing ‘342’, the second task reads the list value stored at the location “buffer.” The value of this program is the value of these two concurrent tasks. Can this programs produce different values on different runs?

2. Write two Forklang programs that have exactly one data race. Each program must share only one location among its threads and must use deref, set!, and call expressions and must evaluate to two different values for different schedules.

3. Modify your programs in the first part by adding sufficient synchronization using lock and unlock expressions, such that these programs no longer have data races (i.e., they are data race free).

4. Modify your programs in the first part by adding sufficient synchronization using synchronized expressions, such that these programs no longer have data races.

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

Step by Step Answer:

Question Posted: