OSDev.org
https://forum.osdev.org/

Pointer Data Problem
https://forum.osdev.org/viewtopic.php?f=1&t=16080
Page 1 of 1

Author:  pcmattman [ Sun Feb 03, 2008 5:18 am ]
Post subject:  Pointer Data Problem

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:
parentptr->me->numchildren++;


My OS outputs some debugging information related to this problem:
Code:
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.

Author:  jal [ Mon Feb 04, 2008 8:49 am ]
Post subject:  Re: Pointer Data Problem

pcmattman wrote:
Code:
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

Author:  pcmattman [ Mon Feb 04, 2008 3:47 pm ]
Post subject: 

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/