OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 3:45 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Pointer Data Problem
PostPosted: Sun Feb 03, 2008 5:18 am 
Offline
Member
Member

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

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject: Re: Pointer Data Problem
PostPosted: Mon Feb 04, 2008 8:49 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 04, 2008 3:47 pm 
Offline
Member
Member

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

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 233 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group