ChipCenter Questlink
SEARCH CHIPCENTER
Search Type:
Search for:




Knowledge Centers
Product Reviews
Data Sheets
Guides & Experts
News
International
Ask Us
Circuit Cellar Online
App Notes
NetSeminars
Careers
Resources
FAQ
EE Times Network
Electronics Group Sites

Answer2


Circuit Cellar Online
THE MAGAZINE FOR COMPUTER APPLICATIONS
Circuit Cellar Online offers articles illustrating creative solutions
and unique applications through complete projects, practical
tutorials, and useful design techniques.

Archive

WHAT'S YOUR ENGINEERING QUOTIENT?

Test Your EQ•Step up to the Plate.

Problem 2In the world of computer science, what is a critical section?


Answer:

A critical section is a piece of code that can only be executed by one thread in order to work correctly. In reality, a set of data items shared by parallel threads usually has multiple critical sections. At any point, at most one thread may be executing one of the critical sections to access the data items.

For instance, consider the following code segment:

int stack[STACK_SIZE];
unsigned stackIndex;
int pop( void ) 
{
int result;
result = stack[--stackIndex];
return result;
}
void push(int value)
{
stack[stackIndex++] = value;
}

The contents of both the pop and push functions should designate critical sections with respect to the array stack and the unsigned variable stackIndex. This is because preemptive multitasking may cause two threads to access the stack at the same time. For instance, two threads may execute --stackIndex and stackIndex++ in parallel, causing confusing symptoms.

2-00


For questions or comments about
Test Your EQ, e-mail eq@circuitcellar.com
.
Click here to get your listing up.

Copyright © 2003 ChipCenter-QuestLink
About ChipCenter-Questlink  Contact Us  Privacy Statement   Advertising Information  FAQ