Files
clang-p2996/lldb/test/API/functionalities/thread/exit_during_expression/main.c
Pavel Labath 053b0634ea [lldb] Increase timeout in TestExitDuringExpression
200 microseconds is not enough time for any expression to execute
reliably. On linux, calling pthread_exit can result in call to dlopen,
which cannot complete in that time, particularly when running under a
debugger.

On linux, this test failed all the time, on macos, about two thirds of
runs were failing.  This patch increases the timeout to 100ms, which is
enough to get it passing reliably on linux, though I wouldn't be
surprised if an even bigger timeout would be needed for remote test
runs.
2020-05-22 12:47:34 +02:00

39 lines
852 B
C

#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
static unsigned int g_timeout = 100000;
int function_to_call() {
errno = 0;
while (1) {
int result = usleep(g_timeout);
if (errno != EINTR)
break;
}
pthread_exit((void *)10);
return 20; // Prevent warning
}
void *exiting_thread_func(void *unused) {
function_to_call(); // Break here and cause the thread to exit
return NULL;
}
int main() {
char *exit_ptr;
pthread_t exiting_thread;
pthread_create(&exiting_thread, NULL, exiting_thread_func, NULL);
pthread_join(exiting_thread, &exit_ptr);
int ret_val = (int)exit_ptr;
usleep(g_timeout * 4); // Make sure in the "run all threads" case
// that we don't run past our breakpoint.
return ret_val; // Break here to make sure the thread exited.
}