Currently IVar are a bit brittle when shared between many writer threads:
i = IVar.new
Thread.new { i.set(42) }
Thread.new { i.set(43) }
one of them will fail due to MultipleAssignmentError
I was wondering about a safer method like IVar#set_unless_assigned returning true if the operation succeeded, false otherwise.
Given that IVars are a well defined entity in literature, do you think is a good idea to add this method to IVar or should we create a new entity (maybe called AtomicIVar or Probe)?
Currently IVar are a bit brittle when shared between many writer threads:
one of them will fail due to MultipleAssignmentError
I was wondering about a safer method like
IVar#set_unless_assignedreturning true if the operation succeeded, false otherwise.Given that
IVars are a well defined entity in literature, do you think is a good idea to add this method toIVaror should we create a new entity (maybe calledAtomicIVarorProbe)?