feat(util/stackinfo): implement get_stack_size (Mac OSX version)

This commit is contained in:
Soonho Kong 2013-12-01 22:18:01 -05:00
parent a2d6918348
commit 4de3b772fd
2 changed files with 31 additions and 2 deletions

View file

@ -10,8 +10,16 @@ Author: Leonardo de Moura
using namespace lean;
static char foo(int i) {
#define SZ 1000000
char buffer[SZ];
#define SZ_FOO 1000000
char buffer[SZ_FOO];
buffer[i] = i;
std::cout << get_available_stack_size() << "\n";
return buffer[i];
}
static char bar(int i) {
#define SZ_BAR 10000
char buffer[SZ_BAR];
buffer[i] = i;
std::cout << get_available_stack_size() << "\n";
return buffer[i];
@ -23,8 +31,16 @@ static void tst1() {
std::cout << get_available_stack_size() << "\n";
}
static void tst2() {
std::cout << get_available_stack_size() << "\n";
bar(10);
std::cout << get_available_stack_size() << "\n";
}
int main() {
save_stack_info();
tst1();
save_stack_info();
tst2();
return has_violations() ? 1 : 0;
}

View file

@ -16,6 +16,19 @@ namespace lean {
size_t get_stack_size() {
return LEAN_WIN_STACK_SIZE
}
#endif
#ifdef __APPLE__
size_t get_stack_size() {
pthread_attr_t attr;
memset (&attr, 0, sizeof(attr));
pthread_attr_init(&attr);
size_t result;
if (pthread_attr_getstacksize(&attr, &result) != 0) {
// pthread_attr_getstacksize is supposed to return 0
throw stack_space_exception();
}
return result;
}
#else
size_t get_stack_size() {
pthread_attr_t attr;