Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can't make the cache immutable because then it will be empty at start and stays that way ;)

The cache has to mutate and be shared as that's the work completed list. As each thread completes a bit of work (visits a node) it needs to communicate it with the other threads.



In Scala, its:

    var cache = Seq(1,2,3)
    cache :+= 4
The cache is immutable and freely shareable. Any other thread and come in and read it and be guaranteed that its current state is valid.


:+= Returns A copy of this sequence with an element appended.

Meaning the cache is no longer shared as all threads end up having a thread local cache. You can't update shared changing state and have immutability at the same time.

Immutability is great when one can have it but sometimes its not possible. Shared changing state is something to be avoid as much as possible but sometimes we need it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: