hi ... I have a problem. and deadline is tommorow ... (my own fault)
I'm solving missionaries and cannibals problem in c++, with threads.
I need an infinite loop. I chose while. The problem is, program locks
down even before reaching the while loop, or any other command.
this is the code, simplified but stil the same problem:
------------------------------------
#include <stdio.h>
#include <values.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <thread.h>
#include <stdlib.h>
#include <synch.h>
#include <time.h>
/* other functions, commented*/
void *camac(void *obala_vanjska) {
camac_obala = *(int *)obala_vanjska;
while (1)
{
sleep(1);
printf("~~~~~~~~~~~~~~~~");
sleep(1);
}
}
int main()
{
printf("EVEN THIS IS NOT SHOWING!!!!!");
int ob=1;
if(thr_create(NULL, 0, camac, (void *) &ob, THR_BOUND | THR_NEW_LWP,
NULL) != 0){
printf("error(camac)!\n");
exit(1);
}
/* other code, commented*/
while (thr_join(NULL, NULL, NULL)==0) {};
return 0;
}
-----------------------------------------
you will have my eternal gratitude if you help!
cheers, Ivo