Skip to content

Commit

Permalink
Set all created threads to 8MB stacksize.
Browse files Browse the repository at this point in the history
Fixes musl systems where non-main pthreads have much smaller stacksizes than Linux.
  • Loading branch information
FeepingCreature committed Feb 27, 2023
1 parent c6e1a26 commit fd9a483
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/c/pthread.nt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern(C) int pthread_mutexattr_settype(pthread_mutexattr_t* attr, int type);
struct pthread_cond_t
{
// __SIZEOF_PTHREAD_COND_T is like 48?
long a; long b; long c; long d; long e; long f;
long a, b, c, d, e, f;
}

extern(C) int pthread_cond_init(pthread_cond_t*, void* attr);
Expand All @@ -49,7 +49,15 @@ void call_thread_dg(void* arg) {
dg();
}

extern(C) int pthread_create(pthread_t* thread, void* attr, void function(void*) start_routine, void* arg);
struct pthread_attr_t
{
// __SIZEOF_PTHREAD_ATTR_T?? Iunno? 64?
long a, b, c, d, e, f, g, h;
}

extern(C) int pthread_create(pthread_t* thread, pthread_attr_t* attr, void function(void*) start_routine, void* arg);
extern(C) int pthread_attr_init(pthread_attr_t* attr);
extern(C) int pthread_attr_setstacksize(pthread_attr_t* attr, size_t stacksize);

struct pthread_key_t {
int value;
Expand Down
6 changes: 5 additions & 1 deletion src/std/thread.nt
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ private class Thread

this(this.pool) { runDg = &run; }
void start() {
pthread_create(&thr, null, &call_thread_dg, &runDg);
// placeholder that's definitely (I'd hope so!) large enough for a pthread_attr_t.
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 8*1024*1024);
pthread_create(&thr, &attr, &call_thread_dg, &runDg);
}
void run() {
while (true) {
Expand Down

0 comments on commit fd9a483

Please sign in to comment.