I have the following Main program:
int main(int argc, char** argv) {
/*checkParameters(argc,argv);*/
if (pthread_create(&supplierid, NULL, &supplier, NULL) != 0);
error("ERROR creating supply threads \n");
}
void *supplier () {
printf("hello? \n");
while (timeremaining >= 0) {
printf("\n the stock is %d" , stock);
printf("\n the supply ies %d", supply);
timeremaining--;
if (stock + supply > cap_max)
stock = cap_max;
else
stock = stock + supply;
sleep(0.1);
}
exit(EXIT_SUCCESS);
}
Ok well, 95% of the time I run this program I get Error creating supply thread. And it never prints hello.
This makes no sense. It just 1 thread.
thanks in advance.
You have a semicolon after your
ifstatement:This means that the statement that appears to be nested within the
ifstatement is not actually nested at all and will always execute regardless of the condition. Specifically, C is interpreting your code to meanTo fix this, remove the stray semicolon.
Hope this helps!