Re: multi thread app and often variable accessing



Begin Curiosity:
> Also, the hardware must have something like the Pentium CMPXCHG8B [...]
Is it not
sufficient to be able to write an int in one single bus access? ie
have a 32-bit wide data bus
Or is that exactly the point? :D

No, in most cases, if you want to atomically increment or decrement a
value (for example, a semaphore or ref count) without locking, you
have to read the value, increment it, then write it only if it's not
changed. The write and check to see if it's not changed must be
atomic, this is where CMPXCHG comes in.

>MOV instructions with a bus-lock prefix, which is slow.
OK, I guess it'd be faster (and leaner) than using a mutex though
But that can't be done in pure C, right?

Maybe, but I don't see how any end-user program (such as one with a
GTK interface) would benefit from the small speed increase. Put such
stuff in another program which merely reports its progress to the gtk
GUI program through a socket or pipe.

End curiosity

And Yeti's right, this stuff can lead to months of head scratching
unless you know what you're doing. I know I don't, so I'll not
potentially mislead you any more.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]