Mutex: Difference between revisions

1,158 bytes added ,  4 years ago
julia example
(Add task markup)
(julia example)
Line 522:
 
The "synchronized" keyword actually is a form of [[monitor]], which was a later-proposed solution to the same problems that mutexes and semaphores were designed to solve. More about synchronization may be found on Sun's website - http://java.sun.com/docs/books/tutorial/essential/concurrency/sync.html , and more about monitors may be found in any decent operating systems textbook.
 
 
=={{header|Julia}}==
From the Julia documentation:
 
<lang julia>SpinLock()</lang>
Create a non-reentrant lock. Recursive use will result in a deadlock. Each lock must be matched with an unlock.
 
<lang julia>lock(lock)</lang>
 
Acquire the lock when it becomes available. If the lock is already locked by a different task/thread, wait for it to become available.
 
Each lock must be matched by an unlock.
 
<lang julia>unlock(lock)</lang>
Releases ownership of the lock.
 
If this is a recursive lock which has been acquired before, decrement an internal counter and return immediately.
 
<lang julia>trylock(lock)</lang>
Acquire the lock if it is available, and return true if successful. If the lock is already locked by a different task/thread, return false.
 
Each successful trylock must be matched by an unlock.
 
<lang julia>islocked(lock)</lang>
Check whether the lock is held by any task/thread. This should not be used for synchronization (see instead trylock).
 
<lang julia>ReentrantLock()</lang>
Creates a re-entrant lock for synchronizing Tasks. The same task can acquire the lock as many times as required. Each lock must be matched with an unlock.
 
 
=={{header|Logtalk}}==
4,102

edits