I don't have a major problem with that. And yes, the weak mapping solution is a hack / temporary solution rather than what I'd really like to get implemented.
In your example would the synchronized(bar) case be a compile time or run time error? Actually, it can't be compile time since the variable you want to lock might be run-time specified. As a matter of fact, doesn't the requirement of 'synchronized' declaration limit the usage area quite a lot?
I mean, say you have a method that is called from any thread:
void process_something(mixed var) { synchronized(var) { process ... } }
Now everything calling this method would have to use 'synchronized' variables. Since it's impossible to know WHAT would be calling this method at compile time, it has to be a runtime error. I don't like that at all. It should just work since there is no inherit need to do anything before "locking" the variable. Sure, you can pre-allocate a mutex but how would that help? Would each svalue contain a pointer to a mutex? That makes no sense since a pointer typically would use the same amount of memory as a mutex lock - how would you indicate that an svalue has a mutex in a way that makes the "preallocate mutex" make any sense?
/ David Hedbor
Previous text:
2003-02-05 18:29: Subject: synchronized
Even in that case the declaration for the variable ought have some sort of flag that it has a mutex, i.e. that the mutex still is declared in one way or the other. E.g:
synchronized mapping foo; mapping bar; ... void f() { synchronized (foo) {...} // Ok. synchronized (bar) {...} // Error: bar doesn't have a mutex. }
There are two reasons for this requirement: As I've said earlier it avoids silently getting mutexes on the wrong things when one happens to mixup variables. Another reason is that it allows more efficient implementation since the space for a mutex can be allocated at compile time. (Note that the proposed solution with a weak mapping is prone to cause gc overhead since the locked things can't be refcount garbed.)
/ Martin Stjernholm, Roxen IS