Need help with state-threads?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

585 Stars 252 Forks Other 88 Commits 8 Opened issues


Light-weight thread library for C/C++ coroutine (similar to goroutine), for high performance network servers.

Services available


Need anything else?

Contributors list


Fork from, patched for SRS.


For original ST without any changes, checkout the ST master branch.


state-threads is licenced under MPL or GPLv2.


Get code:

git clone -b srs

For Linux:

make linux-debug

For OSX:

make darwin-debug

For Cygwin(Windows):

make cygwin64-debug

For Linux aarch64, which fail with

Unknown CPU architecture
make linux-debug EXTRA_CFLAGS="-D__aarch64__"

Linux with valgrind:

make linux-debug EXTRA_CFLAGS="-DMD_VALGRIND"

Remark: User must install valgrind, for instance, in centos6

sudo yum install -y valgrind valgrind-devel

Linux with valgrind and epoll:


For OSX, user must specifies the valgrind header files:

make darwin-debug EXTRA_CFLAGS="-DMD_HAVE_KQUEUE -DMD_VALGRIND -I/usr/local/include"

Remark: Latest OSX does not support ST, please use docker to run ST.

Branch SRS

The branch srs will be patched the following patches:

GDB Tools


How to debug with gdb under valgrind, read valgrind manual.

About startup parameters, read valgrind cli.

Important cli options:

  1. --undef-value-errors= [default: yes]
    , Controls whether Memcheck reports uses of undefined value errors. Set this to no if you don't want to see undefined value errors. It also has the side effect of speeding up Memcheck somewhat.
  2. --leak-check= [default: summary]
    , When enabled, search for memory leaks when the client program finishes. If set to summary, it says how many leaks occurred. If set to full or yes, each individual leak will be shown in detail and/or counted as an error, as specified by the options
  3. --track-origins= [default: no]
    , Controls whether Memcheck tracks the origin of uninitialised values. By default, it does not, which means that although it can tell you that an uninitialised value is being used in a dangerous way, it cannot tell you where the uninitialised value came from. This often makes it difficult to track down the root problem.
  4. --show-reachable= , --show-possibly-lost=
    , to show the using memory.

UTest and Coverage

First of all, download google test to

, check by:
ls -lh utest/gtest/include/gtest/gtest.h >/dev/null && echo yes

To make ST with utest and run it:

make linux-debug-gcov && ./obj/st_utest

For macOS:

make darwin-debug-gcov && ./obj/st_utest

Run utest without coverage:

make darwin-debug-utest && ./obj/st_utest

Then, install gcovr for coverage:

yum install -y python2-pip &&
pip install lxml && pip install gcovr

For macOS:

pip3 install gcovr

Finally, run test and get the report

mkdir -p coverage &&
gcovr -r . -e LINUX -e DARWIN -e examples --html --html-details -o coverage/st.html &&
open coverage/st.html

Note: We ignore

which is

Or just run locally:

bash auto/

Docs & Analysis

  • Introduction:
  • API reference:
  • Programming notes:

  • How to porting ST to other OS/CPU?

  • About setjmp and longjmp, read setjmp.

  • About the stack structure, read stack

  • About asm code comments, read #91d530e.

  • About the scheduler, read #13-scheduler.

  • About the IO event system, read #13-IO.

  • Code analysis, please read #15.

Winlin 2016

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.