---
name: "rt_sem_init"
section: "2"
platform: "linux"
package: "rtlinux"
version: "2.0rel-1"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/rt_sem_init"
---

# rt\_sem\_init(2)

create a semaphore

## NAME

rt\_sem\_init - create a semaphore

## SYNOPSIS

```
#define MODULE
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/errno.h>
#include rt_ipc.h
```

**int rt\_sem\_init(rt\_sem\_t \****sem***, RT\_SEMTYPE** *type***, int** *init\_val***);**

## DESCRIPTION

**rt\_sem\_init** is called to initialize a real-time semaphore.  A semaphore can be used for communication and synchronization among real-time tasks.  Communication between Linux processes and real-time tasks is done using the standard Real-Time Linux RT-FIFO facilities.

*sem* must point to a statically allocated structure. *type* is RT\_SEM\_BINARY or RT\_SEM\_COUNTING. *init\_val* is the initial value of the semaphore (usually 0).

## RETURN VALUE

On success, 0 is returned.  On failure, a negative value is returned as described below.

## ERRORS

- **-EINVAL**

  *init\_val* is negative (or  *type* is RT\_SEM\_BINARY, and  *init\_val* is greater than one.

## BUGS

Priority inheritance is not currently supported.

## AUTHOR

Jerry Epplin \<JerryEpplin@worldnet.att.net\>

## SEE ALSO

[**rt\_task\_ipc\_delete**(2)](/rt_task_ipc_delete/2.md), [**rt\_task\_ipc\_init**(2)](/rt_task_ipc_init/2.md), [**rt\_sem\_destroy**(2)](/rt_sem_destroy/2.md), [**rt\_sem\_post**(2)](/rt_sem_post/2.md), [**rt\_sem\_trywait**(2)](/rt_sem_trywait/2.md), [**rt\_sem\_wait**(2)](/rt_sem_wait/2.md)
