-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 07/01/2014 12:06 PM, Iñaki Baz Castillo wrote: > 2014-07-01 11:44 GMT+02:00 Saúl Ibarra Corretgé > <[email protected]>: >> What if threads are blocked doing something and you shrink the >> threadpool? How do we "kill" those threads? If you are thinking >> about using signals, what if they are doing CPU-intensive work? > > Multiple approachs: > > 1) uv_set_threadpool_size(int) can be called just once (per > loop?). >
You can use the env variable now, we either do it right all the way or we don't. Also note that the threadpool is global, not per loop. > 2) Keep state: > > - int uv__num_threads_in_use: number of active thread being used. - > int uv__threadpool_size: max number of threads (seteable, and at > some point can be least than uv__num_threads_in_use). > > - When calling uv_queue_work(), just add a new thread if > uv__threadpool_size > uv__num_threads_in_use. Otherwise enqueue > it. > > - When a work ends check if (uv__threadpool_size < > uv__num_threads_in_use). If so kill/delete the thread associated to > that work. > > Does it make sense? > Sure. Shrinking the pool would only work after the work is completed, which I guess is ok. A lot of care must be taken with locking since this function needs to take the global mutex. Thread count should never go below 4. Also, when threadpool size changes, what do we do with the memory allocated for those threads? Feel free to submit a PR and I'll take a look! - -- Saúl Ibarra Corretgé bettercallsaghul.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Using GnuPG with Icedove - http://www.enigmail.net/ iQIcBAEBAgAGBQJTso55AAoJEEEOVVOum8BZk4sQAI/IBEummI2guF05FXUXjWVU M5PzzcitplibxOzOuNWlag3MazWWejgJpqX4NfO/VwXT1/1UIKoCSxiztXG79995 JRE/0LT/RhUnq60jJRaJp5m3I7pXUlzNTdeLE8LfjkGvVIuDC+4U5kgXqe22xFnS NITE5P7Pf2pm0yWK9WcXNqsKyq65+v2xxPyNh03SsjtvpctFBFx6ZNhasYKxJe9B a8z6g9bpwmDQskf4uZSiiEOpW4/K+qpdCEDKF9tYixAdigoubaZfg1apd1BlnYjX /t1UHS53Wqa43JxbHXJnis93/7H9lN50b6nsZRSNm20hlS8It+f0tkDFsQJZ/Gsr MLr+lKYROketjAM1BWI/JG7W+Kv9jQf/MpMc3kcaM19gS/BDggBuKS4heWVo4ymV RAlXp8HbCkd3E3lRuNkE/yOLTUVFMqEN1Ouu+FfAKcIiBjx5Xx9MRxfxLxxRP3J8 w51+wm4iuUmHDR9KGEgg0yEnTTatFUPovs94QFid6HtNFm5JwZNytfoAcO50/vhc iRPcMMawr8w6dlT0Z7yusVhmWQ9HIeA2sfms8A56i30TvWFFLTHgKB3KCe7RNG/R eedkJq6B44gLnzHNrfvb3I7FWWqRmqVZiYqjk1wwuqX/aqrEDHrgdpFt+zjz6TDG RwxPx4QgPth9jGMwyeh9 =zWSa -----END PGP SIGNATURE----- -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
