forked from macports/macports-legacy-support
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for bug in pthread_get_stacksize_np
- Loading branch information
1 parent
df195e0
commit 239883b
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <pthread.h> | ||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <stddef.h> | ||
|
||
#ifdef __arm64__ | ||
#define kTooSmallStackSize 0x83000 /* default stack size of non-main thread on Apple silicon */ | ||
#else | ||
#define kTooSmallStackSize 0x80000 /* from LLVM: 1 << 19, default stack size of non-main thread */ | ||
#endif | ||
|
||
void *thread_function(void *arg) { | ||
assert( !pthread_main_np() && "Unknown error, thread should *not* be main." ); | ||
return NULL; | ||
} | ||
|
||
int main() | ||
{ | ||
pthread_t thread; | ||
pthread_t thread_detached; | ||
|
||
assert( !pthread_create(&thread, NULL, thread_function, NULL) && "Unknown error, cannot create thread" ); | ||
assert( (pthread_get_stacksize_np(thread) == kTooSmallStackSize) && "Stack for non-main thread is not the default value" ); | ||
printf("Stack size for non-main thread seems to be ok\n"); | ||
pthread_join(thread, NULL); | ||
|
||
assert( !pthread_create(&thread_detached, NULL, thread_function, NULL) && "Unknown error, cannot create thread" ); | ||
assert( !pthread_detach(thread_detached) && "Unknown error, cannot detach thread" ); | ||
assert( (pthread_get_stacksize_np(thread_detached) == kTooSmallStackSize) && "Stack for detached non-main thread is not the default value" ); | ||
printf("Stack size for detached detached non-main thread seems to be ok\n"); | ||
|
||
assert( pthread_main_np() && "Unknown error, thread should be main." ); | ||
assert( (pthread_get_stacksize_np(pthread_self()) > kTooSmallStackSize) && "Stack for main thread is too small" ); | ||
printf("Stack size for main thread seems to be ok\n"); | ||
|
||
return 0; | ||
} |