curl / Mailing Lists / curl-library / Single Mail


Re: curl handles and multi thread

From: Daniel Stenberg <>
Date: Fri, 10 Nov 2017 23:22:48 +0100 (CET)

On Wed, 8 Nov 2017, surya chandrika via curl-library wrote:

> You must never share the same handle in multiple threads. You can pass the
> handles around among threads, but you must never use a single handle from
> more than one thread at any given time.
> Usecase: (cpp)

> 1. Get a multi handle and post an async req
> 2. If still_running = 1 push them into a global map


> 3. another thread which actively parse this map to select() the handles.
> (one thread dedicated for selection for pending request)

Why another thread? The thread in (2) can't do anything anyway as long as (3)
uses the same handle.

> 4. If an activity is detected another thread from threadpool perform multi
> perform.

Yet another? It's still the same multi handle,so it can't do anything with the
handle unless the other threads using the handle all hold off.

> So using a proper locking mechanism i understand that i should be able to
> perform the above without any exception.

Sure, but the question is then left why you feel you need to use so many

Received on 2017-11-10