diff --git a/trunk/research/st/huge-threads.cpp b/trunk/research/st/huge-threads.cpp new file mode 100644 index 000000000..b87779419 --- /dev/null +++ b/trunk/research/st/huge-threads.cpp @@ -0,0 +1,41 @@ +/* +g++ huge-threads.cpp ../../objs/st/libst.a -g -O0 -DLINUX -o huge-threads && ./huge-threads 32756 +*/ +#include +#include +#include "../../objs/st/st.h" + +void* pfn(void* arg) { + char v[32*1024]; // 32KB in stack. + for (;;) { + v[0] = v[sizeof(v) - 1] = 0xf; + st_usleep(1000 * 1000); + } + return NULL; +} + +int main(int argc, char** argv) { + if (argc < 2) { + printf("Usage: %s nn_coroutines [verbose]\n", argv[0]); + exit(-1); + } + + st_init(); + int nn = ::atoi(argv[1]); + printf("pid=%d, create %d coroutines\n", ::getpid(), nn); + for (int i = 0; i < nn; i++) { + st_thread_t thread = st_thread_create(pfn, NULL, 1, 0); + if (!thread) { + printf("create thread fail, i=%d\n", i); + return -1; + } + if (argc > 2) { + printf("thread #%d: %p\n", i, thread); + } + } + + printf("done\n"); + st_thread_exit(NULL); + return 0; +} +