-
Notifications
You must be signed in to change notification settings - Fork 7
CPU 6. Locks
DotMP provides a locking API. For performance, it's advised to use the .NET lock
keyword. However, this API is provided for those who want a locking API more similar to that which is used in OpenMP.
To create a lock, you can instantiate a DotMP.Lock
object:
DotMP.Lock lck = new DotMP.Lock();
There are several methods you can call on a lock:
If you call:
lck.Set();
The current thread is halted until the lock is obtained, at which point execution proceeds as normal.
If you call:
lck.Unset();
The current lock is freed for other threads to use.
If you call:
bool success = lck.Test();
This attempts to obtain a lock without blocking the thread. If the thread was successful in obtaining the lock, Test()
returns true. If the lock has already been obtained by another thread, Test()
returns false. Again, in neither case is the current thread blocked.
DotMP and all resources on this wiki are licensed under LGPL 2.1. The maintainers make no guarantee of accuracy or efficacy in the materials presented in this wiki.