# Locking scheme

D3 locks groups on a process basis. A port executing a
program is locked from accessing items locked by the previous level.

| Group Update Lock | When an update lock is placed on a group, no other process is allowed into the group for reading or writing. |
| --- | --- |
| Item Lock | When an item lock is placed on an item in a file, other items in that group are allowed to be accessed and updated. A Group lock is placed on the group to prevent shifting, the item is locked and the group is released, leaving the item lock in place. Item locks are used by the FlashBASIC readu, readvu, and matreadu statements and by the Update processor. |

## Example(s)

The following program shows how
the FlashBASIC locked clause can be used. It shows
how to display the file name, port number, and user that has the file
locked:

```
prompt "";item=""
open ’’,’filename’ to f.filename else stop
open ’’,’users’ to f.users else stop
readu item from f.filename,ID locked
 execute "who ":port capturing var
 user.id = field(var," ",2)
 readv name from f.users,user.id,1 else stop
 print "Filename file is locked by port ":port:" ":name
 loop until port = 0 do
 sleep 5
 readu item from f.filename,ID locked else null
 port=system(0)
 repeat
end else stop 202,ID
release
end
```

## See also

- [clear-basic-locks macro](https://d3codex.com/tcl/clear-basic-locks-macro/)
- [clear-locks command](https://d3codex.com/tcl/clear-locks-command/)
- [list-locks command](https://d3codex.com/tcl/list-locks-command/)
- [Port number](https://d3codex.com/definitions/port-number/)
- [system() function](https://d3codex.com/pickbasic-flashbasic/system-function/)
- [ulk](https://d3codex.com/attributedefiningitem/ulk/)
- [unlock-file command](https://d3codex.com/tcl/unlock-file-command/)
- [unlock-group command](https://d3codex.com/tcl/unlock-group-command/)
- [unlock-item command](https://d3codex.com/tcl/unlock-item-command/)
- [what command](https://d3codex.com/tcl/what-command/)

---
Source: https://d3codex.com/definitions/locking-scheme/ - part of the D3Codex reference.
