You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
UniqueLock.lock() and SharedLock.lock() are inline functions of base._SafeLock.lock() and the base._SafeLock.lock() is an inline function of base._SafeLock.try_lock(), too. It seems dangerous implementation considering characteristics of the final destination function base._SafeLock.try_lock()
The base._SafeLock.try_lock() function skips calling lambda if locker returns false. The UniqueLock.lock() and SharedLock.lock() functions, they must hold critical section (locker) until be free. However, they're referencing base._SafeLock.try_lock(), who does not ensure holding critical section in always.
Only in TypeScript level, it's not danger because the parametric function (locker) type must return Promise<void>. However, let's imagine an extra-ordinary case. There's an user does not use TypeScript and wants to use a custom class. Even the custom class does not follow definition of ILockable (or ISharedLockable) and returns Promise. If the custom class returns false, holding critical section in always is not possible.
Conclusion
To avoid such danger, _SafeLock.lock() must have its identical implementation code.
The text was updated successfully, but these errors were encountered:
Summary
_SafeLock.lock()
holds locker until be free_SafeLock.lock()
may not hold the critical section_SafeLock.lock()
must have its identical implementation code.Code occuring the danger
Detailed Story
UniqueLock.lock()
andSharedLock.lock()
are inline functions ofbase._SafeLock.lock()
and thebase._SafeLock.lock()
is an inline function ofbase._SafeLock.try_lock()
, too. It seems dangerous implementation considering characteristics of the final destination functionbase._SafeLock.try_lock()
UniqueLock.lock()
->base._SafeyLock.lock()
->base._SafeLock.try_lock()
SharedLock.lock()
->base._SafeyLock.lock()
->base._SafeLock.try_lock()
tstl/src/base/thread/_SafeLock.ts
Lines 19 to 29 in 3c47bbd
The
base._SafeLock.try_lock()
function skips calling lambda if locker returnsfalse
. TheUniqueLock.lock()
andSharedLock.lock()
functions, they must hold critical section (locker) until be free. However, they're referencingbase._SafeLock.try_lock()
, who does not ensure holding critical section in always.Only in TypeScript level, it's not danger because the parametric function (locker) type must return
Promise<void>
. However, let's imagine an extra-ordinary case. There's an user does not use TypeScript and wants to use a custom class. Even the custom class does not follow definition ofILockable
(orISharedLockable
) and returns Promise. If the custom class returnsfalse
, holding critical section in always is not possible.Conclusion
To avoid such danger,
_SafeLock.lock()
must have its identical implementation code.The text was updated successfully, but these errors were encountered: