| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target split_stack } */ |
| 3 |
/* { dg-require-effective-target pthread_h } */ |
| 4 |
/* { dg-options "-pthread -fsplit-stack" } */ |
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
#include <pthread.h> |
| 8 |
|
| 9 |
/* Use a noinline function to ensure that the buffer is not removed |
| 10 |
from the stack. */ |
| 11 |
static void use_buffer (char *buf) __attribute__ ((noinline)); |
| 12 |
static void |
| 13 |
use_buffer (char *buf) |
| 14 |
{ |
| 15 |
buf[0] = '\0'; |
| 16 |
} |
| 17 |
|
| 18 |
/* Each recursive call uses 10,000 bytes. We call it 1000 times, |
| 19 |
using a total of 10,000,000 bytes. If -fsplit-stack is not |
| 20 |
working, that will overflow our stack limit. */ |
| 21 |
|
| 22 |
static void |
| 23 |
down (int i) |
| 24 |
{ |
| 25 |
char buf[10000]; |
| 26 |
|
| 27 |
if (i > 0) |
| 28 |
{ |
| 29 |
use_buffer (buf); |
| 30 |
down (i - 1); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
static void * |
| 35 |
thread_routine (void *arg __attribute__ ((unused))) |
| 36 |
{ |
| 37 |
down (1000); |
| 38 |
return NULL; |
| 39 |
} |
| 40 |
|
| 41 |
int |
| 42 |
main (void) |
| 43 |
{ |
| 44 |
int i; |
| 45 |
pthread_t tid; |
| 46 |
void *dummy; |
| 47 |
|
| 48 |
i = pthread_create (&tid, NULL, thread_routine, NULL); |
| 49 |
if (i != 0) |
| 50 |
abort (); |
| 51 |
i = pthread_join (tid, &dummy); |
| 52 |
if (i != 0) |
| 53 |
abort (); |
| 54 |
return 0; |
| 55 |
} |