[Libwebsockets] Multiple Threadpool-Worker-Threads on same wsi

Andy Green andy at warmcat.com
Thu Nov 4 07:44:30 CET 2021

On 11/3/21 20:54, Lars Buchholz wrote:

> Just for my understanding: I guess it is not intended to have two or
> more threadpool-worker-threads on the same wsi because the
> lws_threadpool_get_task_wsi(wsi) function would not know which task to
> return. Correct, or do I miss something?

That is correct, "but"... the idea is to conceal the glue that 
synchronizes one thread to one wsi, for each thread in the pool.  That 
matches the pattern where there is a client connection that provokes a 
specific long-lived action, and the wsi needs to remain unblocked and 
responsive in the meanwhile.  The thread can update its status 
periodically to the wsi and it will learn about completion and be able 
to deal with it at wsi layer quickly.  If the wsi goes away, it is 
handled without crashing too.

The "but" is that what your one thread gets up to and how it manages it, 
is open-ended.  So in there, he can spawn child threads and wait on them 
completing before saying that your one thread is done.  In that way the 
pool contains the 1:1 wsi thread pool and sync part, that is able to be 
the coordination point for whatever else you want in there.


More information about the Libwebsockets mailing list