curl-library
Re: How to get downloading progress using multi interface?
Date: Tue, 7 Aug 2007 22:59:21 +0200
On Tue, Aug 07, 2007 at 10:04:22PM +0200, Emil Romanus wrote:
> Are you sure this is safe, even on multi-processor systems?
Not 100%, as I haven't been following processor architectures closely.
> I find it hard to believe that the processors (or cores) lock the words
> they are writing to...
They do, in one way or another - they have to, otherwise the resulting
cache inconsistencies would cause big problems very quickly.
> Even though this might be question of nano seconds
> (or even faster), there is a possibility that the reading core reads
> right in between when the other core is writing the two words needed to
> form up a 32-bit integer which I assume is going to be used. This could
> result in misleading values.
>
> I can agree with you that it's completely safe even without locks when it
> comes to single bytes.
I actually meant "a 32-bit word" when I wrote "word". By your line of
reasoning, the byte is the atomic unit - what makes you think so? It could
be single bits... ;-) Actually, in most cases it is a "cache line" which
changes ownership between the cores of a processor. Tracking individual
bytes would cause too much overhead, so a cache line is much larger. It
seems current Intel/AMD processors use a size of 32 or 64 bytes.
This is getting a bit off-topic, and it's a complicated topic, maybe read
<http://en.wikipedia.org/wiki/CPU_cache> or similar sources.
Anyway, my original remark "you may not need a lock" was a bit academic.
There will be almost no performance hit if the GUI updates its view of the
download progress e.g. once a second, and takes a lock to read all
downloads' state in one go... so do use a lock!
Cheers,
Richard
-- __ _ |_) /| Richard Atterer | GnuPG key: 888354F7 | \/¯| http://atterer.net | 08A9 7B7D 3D13 3EF2 3D25 D157 79E6 F6DC 8883 54F7 ¯ '` ¯Received on 2007-08-07