http://msdn.microsoft.com/en-us/magazine/cc163744.aspx
For a lock to provide mutual exclusion for a region of memory, no writes to that memory can occur without entering the same lock. In a properly designed program, associated with every lock is a region of memory for which it provides mutual exclusion. Unfortunately, there is no obvious artifact of the code that makes this association clear, and yet this information is absolutely critical for anyone reasoning about the multithreaded behavior of the program.
what would be the ideal syntax? what comes to mind is
For a lock to provide mutual exclusion for a region of memory, no writes to that memory can occur without entering the same lock. In a properly designed program, associated with every lock is a region of memory for which it provides mutual exclusion. Unfortunately, there is no obvious artifact of the code that makes this association clear, and yet this information is absolutely critical for anyone reasoning about the multithreaded behavior of the program.
what would be the ideal syntax? what comes to mind is
object myLock = new object(); [Protected(myLock)] MyState myState;x-posted
(no subject)
Date: 2008-07-25 07:51 am (UTC)lock(myLock)
{
tmp = myState;
}
lock(myLock)
{
myState2 += tmp;
}
Тогда как на самом деле всё должно было происходить внутри одного и того же лока, например. Или не должно. Но компилятор больше не ругается. Вдобавок этой штукой, видимо, переменные, а не объекты защищаются, поэтому ссылка может утечь и компилятор ничего не скажет.
Но в целом да, идея вполне правильная. Её даже наверное можно реализовать сторонней тулзой (или на базе fxCop'a какого-нибудь).
(no subject)
Date: 2008-07-25 05:14 pm (UTC)(no subject)
Date: 2008-07-25 05:55 pm (UTC)А кодом я, видимо, что-то имел в виду, но сам не пойму уже. Неважно, в общем смысл понятен, наверное.
(no subject)
Date: 2008-07-31 07:41 pm (UTC)смысл твоего кода неожиданно стал понятен :)
ну да, эта проблема существует и сейчас, никуда не девается, но при чём здесь? повторить, какую проблему решает предложенный мной синтаксис? :)