NetBurner Community Forum

A community of NetBurner users gathering to discuss NetBurner hardware, software, design and projects
It is currently Sat Jan 20, 2018 6:03 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Jan 09, 2018 10:12 am 

Joined: Mon May 12, 2008 10:55 am
Posts: 278
Is it a problem to nest critical sections?
Code:
void func1()
{
    OSCriticalSectionObj protectthis( bus_access );
    // do stuff
    func2();
}

void func2()
{
    OSCriticalSectionObj protectthis( bus_access );
    // More stuff
    func3();
}

void func3()
{
    OSCriticalSectionObj protectthis( bus_access );
    // even more.
}


Top
 Profile  
 
PostPosted: Tue Jan 09, 2018 4:45 pm 

Joined: Thu Apr 24, 2008 3:58 pm
Posts: 713
Yes what you have described will work just fine.




The one area that will get you in trouble is if you have two differnt critical sections....

OSCriticalSectionObj protectthis( bus_access );

OSCriticalSectionObj protectthis( list_access);

In this case its REALLY important that you always enter in the same order....

IE if in one code path you have
OSCriticalSectionObj protectthis( bus_access );
.
.
.
.
OSCriticalSectionObj protectthis( list_access);



And in a differnt code path (in a differnt task)
OSCriticalSectionObj protectthis( list_access);
.
.
.
.

OSCriticalSectionObj protectthis( bus_access );


You will eventually end up hung in a dead lock....
So if ANY path can acquire two or more critical resources then any other path that acquires these resources MUST DO THEM IN THE SAME ORDER.

USER_ENTER_CRITICAL also counts as a critical resource.....for this ordering rule.


Top
 Profile  
 
PostPosted: Wed Jan 10, 2018 10:56 am 

Joined: Mon May 12, 2008 10:55 am
Posts: 278
That's good information. Thank you.


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

All times are UTC - 8 hours [ DST ]


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:  
cron
Powered by phpBB® Forum Software © phpBB Group