PDA

View Full Version : Why does my program behave differently under TotalView control: SIGSTOP problems?



Josh-TotalView-Tech
07-10-2006, 09:50 AM
TotalView uses the SIGSTOP signal to stop processes. On most UNIX systems, system calls can fail with errno set to EINTR when the process receives a SIGSTOP signal. You need to change your code so that it handles EINTR failures. For example: do {
n = read(fd,buf,nbytes);
} while (n < 0 && errno == EINTR);

When a system call is interrupted with a signal (for example, errno == EINTR), you need to retry it. This problem occurs because TotalView stops processes when it updates the displays. If the process is in a system call, the system call fails with EINTR.
For example, assume that your program has the following code fragment: printf("creating scheduler thread...");
if (0 != (status = pthread_create(
&scheduler_thread, &detached_attr,
&scheduler_thread_wrapper, (void *)scheduler)))
{
error_func(ERR_LVL, __FILE__, __LINE__,
"Pthread_create sScheduler, %d, %s",
status, strerror(status));
}

You could restructure it to: printf("creating scheduler thread...");
do {
status = pthread_create(
&scheduler_thread, &detached_attr,
&scheduler_thread_wrapper, (void *)scheduler);
} while (0 != status && errno == EINTR);
if (0 != status) {
error_func(ERR_LVL, __FILE__, __LINE__,
"Pthread_create sScheduler, %d, %s",
status, strerror(status));
}