>From my own experience, altho I'm not that skilled a programmer, sleep()
is not thread-safe.  I believe sleep() sets a global SIGALARM, which is
reset by every thread that calls it, and thus only the last one ever
returns.  Replacing sleep() with nanosleep() or something else that is
thread-safe should solve that problem.

Ken Bolingbroke
[EMAIL PROTECTED]

On Wed, 29 Dec 1999, Steffen Merkel wrote:

> Hello,
> 
> first let me thank all of you for all your great help and the dozens
> of responses I got.
> Unfortunately I have a very strange problem in a multithreaded
> programm I'm writing now. I want to write a programm which
> checks if a server is up by pinging it. I looks like that:
> 
> ######################################
> main(){
>  readconfig()
>  
>  for (every server){ pthread_create(..... startscan() ); }
>  
>   while(1){
>     sleep(1);
>     printf("Main Awake again\n");
>   }
> }
> 
> startscan(){
>   ping(server);
>   printf("Going to sleep\n");
>   sleep(1);
>   printf("Awake again!");
> }
> ########################################
> 
> I can see that the servers are getting pinged and that every
> thread goes to sleep. As soon as every thread did it's job and
> the first thread should awake the program get's a SIGSEGV.
> I can't see the message "Awake again" from the first thread but
> I saw that the first thread started to sleep and the last thread
> finished too and the main thread printed "Awake again!".
> Well with my little knowledge of C I would say that there is a
> problem with the sleep function. But as soon as I remove the
> ping() function the programm operates normally and runs forever.
> 
> Can anyone tell me how I can debug such a problem? A program
> which seems to crash because of function which doesn't get executed
> at crash time.
> 
> Meanwhile I'm going mad with those threads because the program
> worked fine using fork(). Unfortunately it takes too much ram to
> fork a process for every server. That's the reason I want to use
> threads.
> 
> Steffen
> 
> PS: Sorry that I have to bother you again with my incompetence.
> 
> Please reply directly to me because I'm not on the list.
> 
> 
> 
> To Unsubscribe: send mail to [EMAIL PROTECTED]
> with "unsubscribe freebsd-hackers" in the body of the message
> 



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to