Skip to content

Commit

Permalink
Give replace a return value
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Mar 18, 2024
1 parent 6edc62d commit 1e53a17
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/core/feudalism.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ class Mutex[ValueType](initial: ValueType):
count = 0
notify()

def replace(lambda: ValueType => ValueType): Unit =
def replace(lambda: ValueType => ValueType): ValueType =
synchronized:
while count != 0 do wait()
count = -1

value = lambda(value)

val result = value

synchronized:
count = 0
notify()

result

class Semaphore():
private var count: Int = 0
Expand Down

0 comments on commit 1e53a17

Please sign in to comment.