Re: [Openslp-devel] slptool hangs on AIX?
Brought to you by:
jcalcote
|
From: John C. <joh...@gm...> - 2012-10-30 18:13:56
|
Hi Jim, On Tue, Oct 30, 2012 at 10:54 AM, Jim Marshall < jim...@wb...> wrote: > Hi, > Been testing the AIX build I have and the agent is working fine but when > I invoke slptool it basically hangs. Stepping into the code we get to > libslp_handle.c line 66 > > if (SLPAtomicInc(&s_OpenSLPHandleCount) == 1) > > The SLPAtomicInc function does this on AIX: > > return (intptr_t)fetch_and_add((atomic_p)pn, 1); > > This is the cause of the hang, because fetch_and_add "[...] returns the > original value of the variable" (from the man page), in this case '0'. When > this happens the code enters a while loop > Well, that's kind of useless, isn't it? It should be replaced with: return (intptr_t)fetch_and_add((atomic_p)pn, 1) + 1; The idea here is to atomically increment the value stored at pn. If two threads try to do it at once, then they could both read the value, increment it and both write the same value back out. The use of atomic_add should cause both threads to actually increment the value, regardless of how in-sync they are on their attempts to update the value. It's only a side-effect (that we take advantage of) that most atomic incs return the newly updated value. Since the AIX version returns the original value, and we're guaranteed to read/update/write atomically when we add 1 to that original value, then we can assume that the value we get back PLUS ONE is our actual desired return value. I'll fix it. John |