Max Lybbert
Posts: 314
Nickname: mlybbert
Registered: Apr, 2005
|
|
Re: Other Programmers and Shared-Memory Concurrency
|
Posted: Sep 18, 2007 2:27 PM
|
|
The "other programmers" motto reminded me of Blub langauges ( http://www.paulgraham.com/avg.html , and yes, I know that Paul Graham thinks my favorite languages are Blub languages). But, ...
> > I'm really disappointed that people keep chanting the > > 'nobody can write correct concurrent code because it is > > too complicated' mantra. ... > > I'm not saying "correct concurrent code," but rather > "correct code using shared memory threading." ... > > And yes, in my experience, it really is rocket science. > I've had numerous periods in my life where I have thought > that it wasn't, and then that illusion has been dashed. > Enough times that I don't believe it anymore. ... > > > Concurrent code can definitely turn into debugging hell > > with race conditions and vague problems. If you choose > > to work at that level. > > Well, that's the problem. You don't get to choose, because > you aren't guarded from those things, even if you think > you are.
Not too long ago, I hoped to avoid a lot of locking trouble through the type engine. Basically: (1) create only <code>unlocked_access_variables</code>, (2) define a conversion between <code>unlocked_access_variables</code> and <code>locked_access_variables</code> that does the necessary locking/unlocking, and (3) defining all functions to take <code>locked_access_variables</code>.
If I pass an unlocked variable to a function expecting a locked variable, what will happen? The variable will be converted to a locked variable (locking the underlying data), passed to the function, and (depending on the language) destroyed at the end of the function scope, thereby unlocking the data. And if the function calls another function, it will pass the *locked* copy of the data.
So what do I get up at this high altitude? First, I get to worry about the compiler optimizing away my locking or unlocking code. Second, I get to worry about deadlock unless I can guarantee that all variables are locked in the same order every time (which may mean that all function signatures have to list certain variables in certain orders). Oh, and I get to worry about people trying to control access to my objects with semaphores in some places and mutexes in others, and spinlocks in others. And I have a hunch that there are other things to worry about.
It may be time to say that shared data is just a bad way to do things. For all of it's anti-Blubness, Lisp still has limits.
|
|