Page 1 of 1

Pointer Data Problem

Posted: Sun Feb 03, 2008 5:18 am
by pcmattman
Hi everyone,

I'm having some issues in my thread creation function. Each thread setup needs to increment the parent task pointer's "numchildren" element so that the next thread is placed into the correct location in the address space (ie, stacks and whatnot).

This is the code:

Code: Select all

parentptr->me->numchildren++;


My OS outputs some debugging information related to this problem:

Code: Select all

process newcntx = 15434d, newentry = 15437b
final esp is 0xe0000fbc
pointer = 15437b/154367, 1 children
pointer = 15437b/154367, 2 children
final esp is 0xe0000fbc
pointer = 15437b/154367, 1 children
pointer = 15437b/154367, 2 children


You can see that both addresses are equal (the second address in the pointer = lines is the address of the numchildren element). The "final esp..." line is printed during thread creation (as you can see, two threads are created here).

I've tried setting the pointer as volatile but that doesn't solve anything. Any ideas would be greatly appreciated.

Re: Pointer Data Problem

Posted: Mon Feb 04, 2008 8:49 am
by jal
pcmattman wrote:

Code: Select all

parentptr->me->numchildren++;


I haven't analyzed your problem in-depth, but one big (potential) problem with this code is that it is not athomic, so more than one thread may access 'numchildren' at the same time giving unpredictable results.


JAL

Posted: Mon Feb 04, 2008 3:47 pm
by pcmattman
This is actually run with interrupts disabled, so no other threads will access the parent pointer. I did figure it out though, it turned out I was overwriting the incremented value when the process was created :oops: .