C: Minimal pthread mutex Beispiel

English Deutsch
pthread_example.c
#include <pthread.h>
int main() {
    // Mutex erstellen
    pthread_mutex_t mutex;
    pthread_mutex_init(&mutex, NULL /* Standard-Mutex-Attribute */);
    // Sperren
    pthread_mutex_lock(&mutex);
    // Entsperren
    pthread_mutex_unlock(&mutex);
    // Aufräumen
    pthread_mutex_destroy(&mutex);
}

So kompilieren Sie:

compile_pthread.sh
gcc -o main main.c -pthread

Check out similar posts by category: C/C++