Threads in redox using `gcc` : not able to compile `.c` program
Created by: sinkarharshad
Reproduction: gcc threadsinredox.c -o threadsinredox
Expected behavior: I should get output as stated below: (Which I am getting in Linux)
pi@raspberrypi:~/Desktop $ ./threadsinlinux
First thread 0
First thread 1
First thread 2
First thread 3
First thread 4
First thread 5
First thread 6
First thread 7
First thread 8
First thread 9
Second thread 0
Second thread 1
Second thread 2
Second thread 3
Second thread 4
Second thread 5
Second thread 6
Second thread 7
Second thread 8
Second thread 9
Main function after p_thread create
First Thread ret1 = 0
Second Thread ret2 = 0
Actual behavior:
redox login: user
Welcome to Redox OS!
ion: unable to get config root: App data directories not supported
user:~# gcc threadsinredox.c -o threadsinredox
threadsinredox.c:8:1: error: unknown type name 'pthread_mutex_t'
pthread_mutex_t lock;
^~~~~~~~~~~~~~~
threadsinredox.c: In function 'main':
threadsinredox.c:12:2: error: unknown type name 'pthread_t'
pthread_t thread1, thread2;
^~~~~~~~~
threadsinredox.c:18:9: warning: implicit declaration of function 'pthread_create'; did you mean 'pthread_atfork'? [-Wimplicit-function-declaration]
ret1 = pthread_create(&thread1, NULL, myfunc, (void *) msg1);
^~~~~~~~~~~~~~
pthread_atfork
threadsinredox.c:21:2: warning: implicit declaration of function 'pthread_mutex_lock'; did you mean 'pthread_atfork'? [-Wimplicit-function-declaration]
pthread_mutex_lock(&lock);
^~~~~~~~~~~~~~~~~~
pthread_atfork
threadsinredox.c:23:2: warning: implicit declaration of function 'pthread_mutex_unlock'; did you mean 'pthread_atfork'? [-Wimplicit-function-declaration]
pthread_mutex_unlock(&lock);
^~~~~~~~~~~~~~~~~~~~
pthread_atfork
threadsinredox.c:25:2: warning: implicit declaration of function 'pthread_join'; did you mean 'pthread_atfork'? [-Wimplicit-function-declaration]
pthread_join(thread1, NULL);
^~~~~~~~~~~~
pthread_atfork
My .c
Program(threadsinredox.c
):
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
void *myfunc(void *myvar);
pthread_mutex_t lock;
int main (int argc, char *argv[])
{
pthread_t thread1, thread2;
const char *msg1 = "First thread";
const char *msg2 = "Second thread";
int ret1, ret2;
//Arguements: 1. thread 2. to set thread attributes 3.//
//start routine 4. arg: to be passed to start the routine//
ret1= pthread_create(&thread1, NULL, myfunc, (void *) msg1);
ret2= pthread_create(&thread2, NULL, myfunc, (void *) msg2);
pthread_mutex_lock(&lock);
printf("Main fucntion after p_thread create\n");
pthread_mutex_unlock(&lock);
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
printf("First Thread ret1 = %d\n", ret1);
printf("Second Thread ret2 = %d\n", ret2);
return 0;
}
void *myfunc (void *myvar)
{
char *msg;
msg = (char *) myvar;
int i;
pthread_mutex_lock(&lock);
for (i=0; i<10; i++)
{
printf("%s %d\n", msg, i);
//sleep(1);
}
pthread_mutex_unlock(&lock);
return NULL;
}
Is it possible to compile this program in redox? Appreciate your time, thank you.