470,870 Members | 1,406 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

Need help ... tnx

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

May 30 '06 #1
3 1716
I didn't copy it, variable "camac_obala" is a global variable (int)...
but I think that's not a problem here.

sorry

tnx again

May 30 '06 #2
* Zmakhu:
printf("EVEN THIS IS NOT SHOWING!!!!!");

you will have my eternal gratitude if you help!


It will help to flush your output buffers.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 30 '06 #3
yay, that was it, tnx! It was working, just was not displaying!

I never fully understood why do this things happen.

Oh well my project is uploaded to college server, and I can finally get
some sleep.

cheers

May 30 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sofia | last post: by
6 posts views Thread by Robert Maas, see http://tinyurl.com/uh3t | last post: by
reply views Thread by Gregory Nans | last post: by
8 posts views Thread by JustSomeGuy | last post: by
2 posts views Thread by Michael R. Pierotti | last post: by
8 posts views Thread by skumar434 | last post: by
reply views Thread by U S Contractors Offering Service A Non-profit | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.