Pointer Data Problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Freenode IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Pointer Data Problem

Post 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.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Pointer Data Problem

Post 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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Freenode IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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: .
Post Reply