Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 3 page number 77 #2

Open
somucslive opened this issue Oct 16, 2022 · 0 comments
Open

Chapter 3 page number 77 #2

somucslive opened this issue Oct 16, 2022 · 0 comments

Comments

@somucslive
Copy link

"We consider two threads T1 and T2, which call the releaseCopy method. They both
read the state of the Entry object and create a new state object nstate, which is Idle.
Let's assume that the thread T1 executes the compareAndSet operation first and
returns the old Copying object c from the releaseCopy method. Next, let's assume
that a third thread T3 calls the acquireCopy method and changes the state of the
Entry object to Copying(1). If the thread T1 now calls the acquireCopy method
with the old Copying object c, the state of the Entry object becomes Copying(2).
Note that at this point, the old Copying object c is once again stored inside the atomic
variable state. If the thread T1 now attempts to call compareAndSet, it will succeed
and set the state of the Entry object to Idle
. Effectively, the last compareAndSet
operation changes the state from Copying(2) to Idle, so one acquire is lost."

Please correct me If I'm wrong.

  1. As two threads T1 and T2 are in copying state the Entry object will be Entry(state = Copying(n=2)), so T1 or T2 will set nstate = Copying(n = 1) instead of Idle
  2. It should be thread T2 [which attemts to call compareAndSet] instead of T1
@somucslive somucslive changed the title page number 77 Chapter 3 page number 77 Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant