DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:locking

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
devel:locking [2008-10-03 18:31]
andi
devel:locking [2014-04-20 17:21] (current)
2001:4dd0:ff00:8eb9:2514:1931:19a7:1575 old revision restored (2012/08/05 18:42)
Line 9: Line 9:
 Checking for an existing lock is handled by the [[xref>​checklock()]] function. This function will also take care of removing stale lock files. Checking for an existing lock is handled by the [[xref>​checklock()]] function. This function will also take care of removing stale lock files.
  
 +Due to current limitations of the design, the [[xref>​lock()]],​ [[xref>​unlock()]] and [[xref>​checklock()]] lack proper lock atomicity. [[xref>​lock()]] performs lock stealing: it replaces the lock of another process unconditionally.
 +
 +The typical program flow:
 +
 +<code php>
 +if (!checklock($id)) {
 +    lock($id);
 +    // work
 +    unlock($id);​
 +} else {
 +    // error
 +}
 +</​code>​
 +
 +avoids lock stealing in the typical case, where the attempts to lock a page are few and far between. However, in a scenario of two concurrent processes, where the [[xref>​checklock()]] function is called in the first process, then it is called again in the second process leaves both processes assuming that they are free to lock the page. One of them will inadvertently steal the lock from the other.
devel/locking.1223051502.txt.gz ยท Last modified: 2012-08-05 18:42 (external edit)