diff --git a/CHANGELOG.md b/CHANGELOG.md index 6039eb67..44396f72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Features - Initiate major garbage collections faster after allocating a huge object (larger than 500K). This allows the system to reclaim the memory faster and keep overall memory usage low for certain workloads. - Cyclone will no longer memoize pure functions by default. +- Added build option `CYC_PTHREAD_SET_STACK_SIZE` to allow Cyclone to specify a thread stack size rather than using the OS default. Bug Fixes diff --git a/Makefile b/Makefile index f4fb4842..2b1ace0d 100644 --- a/Makefile +++ b/Makefile @@ -197,6 +197,7 @@ mstreams.o : mstreams.c $(HEADERS) runtime.o : runtime.c $(HEADERS) $(CCOMP) -c \ + -DCYC_PTHREAD_SET_STACK_SIZE=$(CYC_PTHREAD_SET_STACK_SIZE) \ -DCYC_INSTALL_DIR=\"$(PREFIX)\" \ -DCYC_INSTALL_LIB=\"$(LIBDIR)\" \ -DCYC_INSTALL_BIN=\"$(BINDIR)\" \ diff --git a/Makefile.config b/Makefile.config index 8a2871ae..d31e4d23 100644 --- a/Makefile.config +++ b/Makefile.config @@ -13,6 +13,11 @@ CYC_PROFILING ?= CYC_GCC_OPT_FLAGS ?= -O2 #CYC_GCC_OPT_FLAGS ?= -g +# Change this to 1 to use a custom stack size for threads. +# Required on platforms such as Alpine Linux that use a +# very small stack by default. +CYC_PTHREAD_SET_STACK_SIZE ?= 0 + OS = $(shell uname) CC ?= cc diff --git a/runtime.c b/runtime.c index 71fe550f..ce0d9634 100644 --- a/runtime.c +++ b/runtime.c @@ -6823,28 +6823,12 @@ void *_Cyc_init_thread(object thread_and_thunk) */ object Cyc_spawn_thread(object thread_and_thunk) { -// TODO: if we want to return mutator number to the caller, we need -// to reserve a number here. need to figure out how we are going to -// synchronize access to GC mutator fields, and then reserve one -// here. will need to pass it, along with thunk, to Cyc_init_thread. -// Then can use a new function up there to add the mutator, since we -// already have the number. -/* -how to manage gc mutators. need to handle: -- need to be able to allocate a thread but not run it yet. - maybe have a run level, or status -- need to make mutators thread safe, ideally without major performance impacts -- thread terminates - - should mark mutator as 'done' - - at an opportune moment, free mutator and set it back - to null - -what is the right data structure? is the array OK? or would it be better -to look at the lock-free structures provided by ck? -*/ pthread_t thread; pthread_attr_t attr; pthread_attr_init(&attr); +#if CYC_PTHREAD_SET_STACK_SIZE + pthread_attr_setstacksize(&attr, 1024*1024*8); +#endif pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (pthread_create(&thread, &attr, _Cyc_init_thread, thread_and_thunk)) { fprintf(stderr, "Error creating a new thread\n");