Home > Net >  Command not found errors in Linux using threads
Command not found errors in Linux using threads

Time:11-20

I am working with threads and I am not understanding the errors it's prompting me. I have a feeling I could just be compiling this program incorrectly. Please let me know so I can learn from my mistakes. Here are some pictures of the code and output. I will also supply the code snippet if needed. enter image description here

enter image description here

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

int count = 0;
pthread_mutex_t lock;
void* increment(void* arg)
{
pthread_mutex_lock(&lock);
count  ;
printf("Increment: %d\n", count);
pthread_mutex_unlock(&lock);
}
int main()
{
pthread_mutex_init(&lock, NULL);
pthread_t tid1, tid2;
pthread_create(&tid1, NULL, increment, NULL);
pthread_create(&tid2, NULL, increment, NULL);
pthread_join(tid1, NULL);
pthread_join(tid2, NULL);
pthread_mutex_destroy(&lock);
return 0;
}

CodePudding user response:

You are trying to run a C source file. You can't do that. You need to run a compiled file (of course after you run the compiler). An appropriate command would be ./mutexlock, make note, no .c ending.

  • Related