Sunday 19 February 2012

OS Puzzle: Can it happen?

Consider two different threads are running the same piece of code below. When it will print the following ?

1. x is 7
2. x is 8
3. x is 9
4. x is 10

shared int x; 
x = 10; 
while (1) 

 x = x - 1; 
 x = x + 1; 
 if (x != 10) 
  printf(“x is %d”,x) 
}

Tuesday 7 February 2012

Effective Endian conversion in x86

Instead of Using the bit shift operators, we can use the assembly instruction bswap provided by x86 systems.
I am using the EAX Register for manipulation because it is the same register used for returning value. So i dont need any extra instruction to move my variable to EAX register

Thursday 12 January 2012

Embedded: Edge vs Level Triggered Interrupts




S.No Edge Triggered Interrupts Level Triggered Interrupts
1 Can cause high spurious Interrupts (if there is no signal proper filters, but can be avoided with filters) Minimal Spurious Interrupts
2 If the Pulse is very short it needs dedicated HW to detect it It is easy to detect the Level triggered Interrupts
3 From H/W Perspective more gates and complex to implement Less gates required and Less complex to implement
4 Not good for Interrupt Sharing. As if we dont clear the interrupt immediately it will cause other device interrupt to get lost. (But can be avoided if we clear the interrupt immediately) Good for Interrupt sharing with devices.
5 No Lockup problem If there is any interrupt without the handler to clear it will cause the whole system to Lockup
6 While Processing the interrupt first Clear the interrupt and then process Process the interrupt and then Clear. (or else may get the same interrupt again)


Verdict:  Edge Triggered Interrupts are preferred.