> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sdk-user-guide/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sdk-user-guide/_mcp/server.

# holoscan::FileFIFOMutex

> A class that implements a file-based FIFO mutex.

A class that implements a file-based FIFO mutex.

This class implements a file-based mutex that can be used to synchronize multiple processes. It uses a lock file to synchronize the processes and a queue file to store the process IDs of the processes that are waiting to acquire the lock.

```cpp showLineNumbers={false}
#include <holoscan/file_fifo_mutex.hpp>
```

---

## Constructors

### FileFIFOMutex \[#filefifomutex]

#### Overload 3

```cpp showLineNumbers={false}
holoscan::FileFIFOMutex::FileFIFOMutex(
    std::string file_path
)
```

Constructs a new file-backed mutex at the given path and a queue file at `file_path.queue`, if not already present.

It also opens both the files.

**Parameters**

**`file_path`** `std::string`

The path to the mutex file.

---

#### Deleted overloads

The following overloads are deleted to prevent misuse:

```cpp showLineNumbers={false}
holoscan::FileFIFOMutex::FileFIFOMutex(const FileFIFOMutex &) = delete;
holoscan::FileFIFOMutex::FileFIFOMutex() = delete;
```

### Destructor \[#destructor]

### \~FileFIFOMutex

```cpp showLineNumbers={false}
holoscan::FileFIFOMutex::~FileFIFOMutex()
```

Unlocks the mutex if it was locked.

Closes the queue and lock files.

---

## Assignment operators

### operator= \[#operator\_assign]

```cpp showLineNumbers={false}
FileFIFOMutex & holoscan::FileFIFOMutex::operator=(
    const FileFIFOMutex &
) = delete
```

---

## Methods

### set\_wait\_time\_ms \[#setwaittimems]

```cpp showLineNumbers={false}
void holoscan::FileFIFOMutex::set_wait_time_ms(
    int wait_time_ms
)
```

Sets the wait time for the lock.

The wait time is applied when the queue file is being locked. If the queue file is not available for lock within the wait time, then the lock is not acquired. If the wait time is less than or equal to 0, then it blocks until the lock is acquired.

**Parameters**

**`wait_time_ms`** `int`

The wait time in milliseconds.

---

### lock \[#lock]

```cpp showLineNumbers={false}
void holoscan::FileFIFOMutex::lock()
```

Locks the mutex after writing the current process' PID to the queue.

Waits for the queue file to be unlocked to write its own PID to the queue, depending on the wait time.

### unlock \[#unlock]

```cpp showLineNumbers={false}
void holoscan::FileFIFOMutex::unlock()
```

Unlocks the mutex by removing itself from the queue and unlocking the mutex.

### locked \[#locked]

```cpp showLineNumbers={false}
bool holoscan::FileFIFOMutex::locked() const
```

Returns true if the mutex is locked.

**Returns:** false When the mutex is not locked.

---

## Member variables

| Name            | Type                             | Description |
| --------------- | -------------------------------- | ----------- |
| `main_lock_`    | `std::unique_ptr< ScopedFlock >` |             |
| `fd_`           | `int`                            |             |
| `queue_fd_`     | `int`                            |             |
| `pid_`          | `pid_t`                          |             |
| `locked_`       | `bool`                           |             |
| `wait_time_ms_` | `int`                            |             |