===XQuery===
With {{Announce|Version Since BaseX 10}}, the [[BaseX 10#Compilation|lock detection has been fundamentally improved]], by splitting compilation into multiple steps.
Local locks can be applied if it is possible after compile time to associate all database operations with static databases names:
In the following module, lock annotations are used to prevent concurrent write operations on the same file:
<syntaxhighlight pre lang="'xquery"'>
module namespace config = 'config';
file:write-text('config.txt', $data)
};
</syntaxhighlightpre>
Some explanations:
* If a query calls the a reading <code>configbasex:readlock</code> function, a read lock will be acquired for the user-defined {{Code|CONFIG}} lock string before query evaluation.* If an updating <code>configbasex:writelock</code> is called by a query, a write lock will be applied.* If another query calls a <code>configbasex:writelock</code>function, it will be queued until the first query is evaluated.
==Pragmas==
Locks can also be declared via pragmas:
<syntaxhighlight pre lang="'xquery"'>
update:output((# basex:lock CONFIG #) {
file:write('config.xml', <config/>)
})
</syntaxhighlightpre>
The write locks is enforced via the {{Code|Update|update:output}}.
Locks for the functions of a module can also be assigned via option declarations:
<syntaxhighlight pre lang="'xquery"'>
declare option basex:lock 'CONFIG';
update:output(file:write('config.xml', <config/>))
</syntaxhighlightpre>
Once again, a write lock is enforced.