Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What constructs are not possible using Ponylang's lock-free model?

Ponylang is a new language that is lock-free and datarace-free. My impression is that to accomplish this, Ponylang looks at the sentence "if two threads can see the same object, then writes must prohibit any other operation by another thread", and uses a type system to enforce the various special cases. For example, there's a type descriptor that says, "no other thread can see this object", and one that says, "this reference is read-only", and various others. Admittedly my understanding of this is quite poor, and ponylang's documentation is short on examples.

My question is: are there operations possible with a lock-based language that aren't translatable into ponylang's type-based system at all? Also, are there such operations that are not translatable into efficient constructs in ponylang?

like image 381
Kevin Yin Avatar asked Jun 08 '15 07:06

Kevin Yin


1 Answers

[...] are there operations possible with a lock-based language that aren't translatable into ponylang's type-based system at all?

The whole point with reference capabilities, in Pony, is to prevent you from doing things that are possible and even trivial, in other languages, like sharing a list between two threads and add elements to it concurrently. So, yes, in languages like Java, you can share data between threads in a way that is impossible in Pony.

Also, are there such operations that are not translatable into efficient constructs in ponylang?

If you're asking if the lock-based languages can be more efficient in some situations, than pony, then I think so. You can always create a situation that benefits from N threads and 1 lock and is worse when you use the actor model which forces you to pass information around in messages.

This thing is not to see the actor model as superior in all cases. It's a different model of concurrency and problems are solved differently. For example, to compute N values and accumulate the results in a list:

  • In a thread-model you would
    1. create a thread pool,
    2. create thread-safe list,
    3. Create N tasks sharing the list, and
    4. wait for N tasks to finish.
  • In an actor-model you would
    1. create an actor A waiting for N values,
    2. create N actors B sharing the actor A, and
    3. wait for A to produce a list.

Obviously, each task would add a value to the list and each actor B would send the value to actor A. Depending on how messages are passed between actors, it can be a slower to send N values than to lock N times. Typically it will be slower but, on the other hand, you will never get a list with an unexpected size.

like image 117
m4ktub Avatar answered Nov 04 '22 03:11

m4ktub