[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaTask needs your help
- From: David Given <dg@...>
- Date: Mon, 09 Jul 2007 10:58:48 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Thomas Lauer wrote:
[...]
>> if( aTask[i]->running) { // <--- aTask pointer may have been
>> realloc()'ed elsewhere
[...]
> I am not sure that this line is indeed a problem. Isn't checking an int
> an atomic operation? As aTask is declared volatile, it should be
> re-referenced, so a change during the loop would not be a problem
> either.
Ah, but that's not an atomic operation. That line compiles into something like:
; r1 contains i
r0 = aTask ; fetch aTask
r2 = r1 << 2 ; calculate offset into array
r0 = r0 + r2 ; calculate address of pointer in array
r0 = [r0+0] ; dereference pointer to get address of structure
r0 = [r0+42] ; fetch structure member
So if aTask gets modified while this code is in operation, suddenly you'll be
working with a stale pointer. Hilarity ensues.
- --
┌── dg@cowlark.com ─── http://www.cowlark.com ───────────────────
│
│ "Anything that makes people that angry is worth doing again." --- Scott
│ Adams
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGkgbYf9E0noFvlzgRAkloAJ0bgYIvuMj5lbcVuL443gJuev/N2ACgknjx
kCsc33edciRTwDJJsfrnACE=
=ULKu
-----END PGP SIGNATURE-----