Re: [AD] replace xlock/xunlock with synchronized{} |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On 2006-04-05, Jon Rafkind <workmin@xxxxxxxxxx> wrote:
> Would anyone be opposed to replacing all the XLOCK()/XUNLOCK() blocks in
> the x11 code of Allegro with a #define'd syntax that does the same
> thing, with preferably the same name as java's sychnronization keyword
> 'synchronized' ?
>
> Basically do this
>
> #define synchronized for ( XLOCK(); XUNLOCK(); /**/ )
Clever.
> and then instead of
>
> int _xwin_create_window(void)
> {
> int result;
> XLOCK();
> result = (*_xwin_window_creator)();
> XUNLOCK();
> return result;
> }
>
> would be
>
> int _xwin_create_window(void)
> {
> int result;
> synchronized{
> result = (*_xwin_window_creator)();
> }
> return result;
> }
>
> Yes I use Java a lot these days and I find this very clean. Plus it
> would prevent the mistake of forgetting to use XUNLOCK() occasionally.
Unfortunately there is the risk of incorrect but seemingly correct code
like this:
synchronized {
if (foo) {
return 1;
}
}
For a while I was writing mutex lock/unlock pairs as
lock();
{
body
}
unlock();
which I think is more transparent.
Peter