curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl handles and multi thread

From: Daniel Stenberg <daniel_at_haxx.se>
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

Them?

> 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
threads...

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2017-11-10