Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

sleep() within pthread_..() generates Alarm Clock

807575Jul 30 2002 — edited Jul 31 2002
Hi,

when I run the following code the program aboards immediate with the message "Alarm Clock".

Without the usleep() the program seems to run.

(I know that the function call is not syncronized - if you add some mutex you recive the same result).

Why do I recive the Alarm Clock?
How can I run the program without the Alarm Clock message?

thx

Manfred Friedrich


==============================================
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void print_char (void ch)
{
for (int i=0; i<10; i++) {
printf ("%c", *(char*)ch);
usleep(20 * 1000); //"<----- result is an alarm clock signal"
}

printf("\n");
return NULL;
}


int main ()
{
char ch1='-', ch2='*';
pthread_t p1, p2;

while(1){
pthread_create (&p1, NULL, print_char, &ch1);
pthread_create (&p2, NULL, print_char, &ch2);

pthread_join (p1, NULL);
pthread_join (p2, NULL);
}

return 0;
}

===========================================



Compile options:
CC -mt -c lock_n_sleep.cpp
CC lock_n_sleep.o -lpthread -o lock_n_sleep

Version & OS:
uname -a --> SunOS ffzj0yfq 5.7 Generic_106541-02 sun4u sparc SUNW,Ultra-250
CC -V --> CC: WorkShop Compilers 5.0 98/12/15 C++ 5.0
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2002
Added on Jul 30 2002
2 comments
157 views