softwaremill / softwaremill/ox
Actors impl can easily lead to multithreading issues
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 522
- Forks
- 35
- Avg merge
- 45m
- Merged PRs (30d)
- 13
Description
I think the way ask & tell are impl they can lead to unwanted behaviour, i.e. say we have an actor that can calculate the max of a list. We would expect the actor to be called with a readily available list, but a call like:
actorRef.tell(_.max(calcMyList(...)))
means that the actor thread will also have to calculate the list.
The correct way to call it would be:
val l=calcMyList(...)
actorRef.tell(_.max(l))
but this can easily be missed by the developer writing the code, leading to slow throughput of the actor (because it is also calculating arbitrary lists, not just their maximums)
More silly code could lead to unpredictable behaviour:
var i=0
actor.tell(_.addOne(i))
while true do i+=1
// what will be the arg value to addOne?
Is there a solution to this? Maybe if:
actorRef.tell(_.max , calcMyList(...))
where the tell and ask methods take a FunctionN and then separately by-value their arguments like
class ActorRef...:
def tell[A](f:Function1[A,Unit],arg1:A) ...
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the ask and tell implementations referenced in the issue, then trace how closures and their captured arguments are executed. Compare the proposed separate-argument API with the current behavior and determine the intended safety guarantees. Done means an agreed API design that prevents caller-side computation and mutable-value races, with corresponding coverage identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- distributed-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100