The routines cs_ctx_alloc, cs_ctx_drop, ct_init, and ct_exit are thread-unsafe and must be serialized as follows:
Any call to cs_ctx_alloc or cs_ctx_drop must be serialized with other calls to cs_ctx_alloc or cs_ctx_drop.
Additionally, any call to ct_init or ct_exit must be serialized with other calls to ct_init or ct_exit.
You need not worry about this issue if your program allocates and initializes all necessary CS_CONTEXT structures in single-threaded initialization code and performs all context-level cleanup operations in single-threaded cleanup code. An alternative strategy limits the use of a given context structure to a single thread to eliminate the need for serialization.