Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22233

pthread_create exits the program after finishing function

$
0
0

I try to create program that takes power readings about 10 times in one second and start a new thread every second/minute to update mysql database while the main program continues taking readings. But after I use pthread_create function runs once and then program seems to exit. It is my first time trying to do something with pthread and obviously I am doing something wrong. Please help because it seems smart to use new thread to update mysql, so it will not interrupt main program. I will add my code (bit that are important I think)

the function:

void *showreadout(float readout,int l, int s) {  printf("readout: %f loops: %i sec: %i\n",readout,l,s);  return NULL;}

and stuff from main:

      pthread_t thread;      int p = 0, startminute = currentminute(),startsec,u;      float secreadout;      while (startminute == currentminute()) {        startsec = currentsec();        u = 0;        secreadout = 0;        while (startsec == currentsec()) {          secreadout += doloop(pinnumber);          u++;        }        pthread_create(&thread, NULL, showreadout(secreadout/u,u, startsec), NULL);        p++;      }

Viewing all articles
Browse latest Browse all 22233

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>