---
name: Protheus Locks And Deadlocks
slug: protheus-locks-and-deadlocks
category: Quality
description: Protheus Locks And Deadlocks explains RecLock, MsUnlock, SoftLock, LockByName, and transaction scoping in Protheus. Use it to diagnose record locks, deadlocks, and lock leaks, or to apply safer lock ordering and BEGIN SEQUENCE/RECOVER patterns.
github: "https://github.com/thalysjuvenal/advpl-specialist/tree/main/skills/protheus-locks-deadlocks"
language: Shell
stars: 186
forks: 37
install: "npx degit https://github.com/thalysjuvenal/advpl-specialist/tree/main/skills/protheus-locks-deadlocks ~/.claude/skills/protheus-locks-deadlocks"
installs_to: ~/.claude/skills/protheus-locks-deadlocks
source_path: skills/protheus-locks-deadlocks/SKILL.md
collection_size: 18
category_size: 1745
collection_url: "https://dirskills.com/collections/thalysjuvenal/advpl-specialist"
added: 2026-09-06T05:20:29.415Z
last_synced: 2026-09-06T05:20:29.415Z
canonical_url: "https://dirskills.com/skills/protheus-locks-and-deadlocks"
---

# Protheus Locks And Deadlocks

Protheus Locks And Deadlocks explains RecLock, MsUnlock, SoftLock, LockByName, and transaction scoping in Protheus. Use it to diagnose record locks, deadlocks, and lock leaks, or to apply safer lock ordering and BEGIN SEQUENCE/RECOVER patterns.

**Install:**

```bash
npx degit https://github.com/thalysjuvenal/advpl-specialist/tree/main/skills/protheus-locks-deadlocks ~/.claude/skills/protheus-locks-deadlocks
```

## README

# Protheus Locks & Deadlocks

This skill documents the Protheus hybrid locking model -- record-level Workarea locks (`RecLock`/`MsUnlock`) coordinated by DBAccess on top of the underlying RDBMS (PostgreSQL, MSSQL, Oracle) -- and how to diagnose and prevent the lock leaks, contention, and deadlocks that are among the most common production issues. It covers lock API semantics (`RecLock`, `MsUnlock`/`MsUnlockAll`, `SoftLock`, `LockByName`, `TCSqlExec`, `BeginTran`/`EndTran`/`DisarmTransaction`), safe transaction scoping with `BEGIN SEQUENCE/RECOVER`, and live diagnostic procedures per database engine.

Activate this skill when the user reports a "Record locked by user XYZ" error, needs to investigate performance degradation under concurrent load, is writing or reviewing code that locks records, or is designing a batch job over large data sets where lock ordering matters. It does not cover query design or `%nolock%` usage in Embedded SQL (see `query-builder`), general runtime/performance debugging unrelated to locking (see `advpl-debugging`), or `BeginSQL`/`EndSQL` macro syntax (see `embedded-sql`).

| Reference file | Read when |
|---|---|
| reference.md | Always -- lock types table, core lock/transaction APIs, when-to-use guidance |
| patterns-prevention.md | Writing or refactoring code that locks records -- `BEGIN SEQUENCE/RECOVER`, `SoftLock`, transaction scoping, lock ordering rules |
| diagnostics.md | Investigating live lock contention or deadlocks -- `TopMemoStatus`, MonitorActiveLocks, DBAccess monitor, engine-specific SQL lock queries |
