cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: how to write the lock funcition in share interface

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 20 Jan 2006 07:58:02 +0100 (CET)

On Thu, 19 Jan 2006, Yi Li wrote:

>> This program doesn't set the lock or unlock function callbacks with
>> curl_share_setopt(), so using this share multi-threaded is bound to cause a
>> memory mess.

> from the lib506.c in tests, it appears that the lock and unlock callback are
> only needed when you want to mutex your data in multi_threads.

Not *your* data. libcurl's data that you told it to share between multiple
handles.

> In my program, I don't have such data.

You told it to share DNS cache, right? It means that every time libcurl wants
to resolve a host name it'll require a lock, do the resolve dance, and then
unlock again.

> in such case, those callbacks are still needed? What am I going to do in
> those callbacks. Just give a empty function?

You need to make sure that only one thread at a time has the same 'data'
locked at any given time. A mutex!

-- 
  Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
Received on 2006-01-20