Re: [AD] Mini-synchronization API proposal for 4.1.x |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
> > I think that the 'lock anyway and unlock afterwards if needed' approach
> > should work. But does it need to be implemented (see my question below)
>
> That sounds more expensive than necessary.
I'll investigate, because:
- with this method, you have no penalty in 'normal' operation mode, i.e when
mutexes are only locked once,
- I think the OS is clever enough not to really lock another time if the
critical section is already locked by the same thread, and simply increments
the lock count,
- the other solution is of course to conditionally lock:
if (mutex->owner == current_thread_id())
return;
which costs one system call per lock. Moreover, if point #2 is true, it's a
sheer waste of time.
--
Eric Botcazou
ebotcazou@xxxxxxxxxx