Dining Philosophers using C11 threads I wanted to try multithreading out in C, so I did Dining Philosophers using C11 threads with the approach of having one of the philosophers left-handed. Any suggestions?

#include &lt;stdio.h&gt;
#include &lt;threads.h&gt;
#include &lt;stdlib.h&gt;

#define NUM_THREADS 5

struct timespec time1;
mtx_t forks[NUM_THREADS];

typedef struct {
    char *name;
    int left;
    int right;
} Philosopher;

Philosopher *create(char *nam, int lef, int righ) {
    Philosopher *x = malloc(sizeof(Philosopher));
    x-&gt;name = nam;
    x-&gt;left = lef;
    x-&gt;right = righ;
    return x; 
}

int eat(void *data) {
    time1.tv_sec = 1;
    Philosopher *foo = (Philosopher *) data;
    mtx_lock(&amp;forks[foo-&gt;left]);   
    mtx_lock(&amp;forks[foo-&gt;right]);
    printf("%s is eating\n",  foo-&gt;name);
    thrd_sleep(&amp;time1, NULL);
    printf("%s is done eating\n",  foo-&gt;name);
    mtx_unlock(&amp;forks[foo-&gt;left]);
    mtx_unlock(&amp;forks[foo-&gt;right]);
    return 0;
}

int main(void) {
    thrd_t threadId[NUM_THREADS];
    Philosopher *all[NUM_THREADS] = {create("Teral", 0 ,1), 
                    create("Billy", 1, 2), 
                    create("Daniel", 2,3), 
                    create("Philip", 3, 4),
                    create("Bennet", 0, 4)};
    for (int i = 0; i &lt; NUM_THREADS; i++){
        if (mtx_init(&amp;forks[i], mtx_plain) != thrd_success){
            puts("FAILED IN MUTEX INIT!");
            return 0;
        }
    }
    for (int i=0; i &lt; NUM_THREADS; ++i) {
        if (thrd_create(threadId+i, eat, all[i]) != thrd_success) {
            printf("%d-th thread create error\n", i);
            return 0;
        }
    }

    for (int i=0; i &lt; NUM_THREADS; ++i)
        thrd_join(threadId[i], NULL);
    return 0;
}
when calling malloc(), always check the returned value to assure the operation was successful

use meaningful variable names.   x is not a meaningful name and just makes the code more difficult to understand.

it seems the threads.h header file is not available everywhere.  

For portability, suggest changing to the POSIX threads 

#include &lt;pthreads.h&gt; 


and using the related functions like: 

pthread_create() 
pthread_exit()
pthread_join()
pthread_t
pthread_mutex_lock()
pthread_mutex_unlock()


when a function fails, most likely one or more of the Philosopher entities have already been created via malloc()  to avoid a memory leak, those memory allocation pointers need to be passed to free()

When returning out of main, due to an error, return EXIT_FAILURE (or similar value) rather than returning 0 which indicates success.

in main(), the calls to create() need to check the returned value to assure the operation was a success.

the eat() function just zooms through and exits.  This is not the (typical) action of the Dining Philosophers problem.  Suggest searching stackoverflow.com for implementations of the problem and using the overall logic, with some modification for the 'left handed' diner.

The posted code fails to free() the malloc'd memory at the end of the main() function