The program seems to work as intended, but I'm getting this error when compiling:
Code:
$ gcc -O2 -Wall bar.c -o bar -lpthread -lX11 -L/usr/include/curl/lib -lcurl
bar.c: In function ‘main’:
bar.c:257:57: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [-Wincompatible-pointer-types]
pthread_create(&myThreads[i], NULL, execFunc, &t[i]);
^~~~~~~~
In file included from bar.c:14:0:
/usr/include/pthread.h:233:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void * (*)(struct tData *)’
extern int pthread_create (pthread_t *__restrict __newthread,
^~~~~~~~~~~~~~
Relevant code:
Code:
#include<sys/ioctl.h> #include<arpa/inet.h>
#include<unistd.h> /* close() */
#include<linux/if.h> /* struct ifreq */
#include<X11/Xlib.h>
#include<curl/curl.h>
#include<stdlib.h>
#include<pthread.h>
...
struct tData {
const char* cmd;
char* str;
char* tmpStr;
int ready;
unsigned int scroll;
};
void* execFunc(struct tData* td)
{
struct tData* t=(struct tData*) td;
char data[128];
FILE *file = popen(t->cmd, "r");
fgets(data, 128, file);
t->tmpStr = data;
t->ready = 1;
pclose(file);
return NULL;
}
...
int main()
{
#define nThreads 1
pthread_t myThreads[nThreads];
struct tData t[nThreads];
t[0].cmd = "/home/pi/git/weather";
t[0].str = NULL;
t[0].tmpStr = NULL;
t[0].ready = 0;
t[0].scroll = 0;
...
for (i = nThreads; i--;)
{
pthread_create(&myThreads[i], NULL, execFunc, &t[i]);
pthread_detach(myThreads[i]);
}
...
return 0;
}
Any ideas?