Wouldn't it be enough to have a mutex for each object and when such a builtin function is called, all objects which are passed as parameters (including and esp. `self`) are locked?
Wouldn't it be enough to have a mutex for each object and when such a builtin function is called, all objects which are passed as parameters (including and esp. `self`) are locked?
Not to mention that if every object has a mutex associated, the performance will be horrible. Even if the mutexes are not contended, there will be so many atomic compare and swap operations that the interprocessor memory bus will simply die.
If your solution would work, every method in Java would be synchronized by default.
But I think you can add such a behavior in an automatic way.
However, I claim that you can also do it in an automatic way and avoid deadlocks at the same time.
E.g., like this: https://github.com/albertz/automatic_object_locking/blob/mas...