> For the complete documentation index, see [llms.txt](https://dimitar-minchev.gitbook.io/linux-system-programming/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dimitar-minchev.gitbook.io/linux-system-programming/09_threads_sync/12_creating_mutexes.md).

# Създаване и унищожаване на мютекси

```c
#include<pthread.h>
void pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
void pthread_mutex_destroy(pthread_mutex_t *mutex
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
```

Променливите за мютекси трябва да бъдат декларирани с тип **pthread\_mutex\_t** и трябва да бъдат инициализирани, преди да могат да бъдат използвани. Съществуват два начина за инициализиране на променлива от тип мютекс:

* Статично, когато се декларират.
* Динамично, посредством **pthread\_mutex\_init()**. Този метод позволява задаването на атрибути за мютекс обекта.
