3 ms·
Now that's an interesting approach. I proposed something similar for Python 9 years ago.[1] Guido didn't like it. Objects would be either thread-local, shared
by Animats 8y ago
Now that's an interesting approach.
I proposed something similar for Python 9 years ago.[1] Guido didn't like it.
Objects would be either thread-local, shared and locked, or immutable.
Thread-local objects must be totally inaccessible from other threads, and not leakable across thread boundaries, for memory safety. (Python has "thread local" objects now, but it's just naming, and not airtight against leaks. You can assign a thread-local object to a global variable.) Shared and locked objects lock when you enter, unlock when you leave. Objects are thread-local by default, so single-thread programs work as before.
Minimize shared and locked, while using thread-local or immutable objects as much as possible. Locking is needed only for shared and locked objects.
This is almost conventional wisdom today, but 9 years ago, it was too radical.
Retrofitting concurrency is never pretty. But we have to. Individual CPUs are about the same speed per thread that they were a decade ago.
[1] http://animats.com/papers/languages/pythonconcurrency.html http://animats.com/papers/languages/pythonconcurrency.html