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