RSS

Tag Archives: interview question

Mutual Exclusion

The requirement of ensuring that no two concurrent processes are in their critical section at the same time; it is a basic requirement in concurrency control, to prevent race conditions.

Source: Wikipedia

 
Leave a comment

Posted by on June 23, 2015 in General

 

Tags: ,

Producer-consumer Problem

Two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue. The producer’s job is to generate a piece of data, put it into the buffer and start again. At the same time, the consumer is consuming the data (i.e., removing it from the buffer) one piece at a time. The problem is to make sure that the producer won’t try to add data into the buffer if it’s full and that the consumer won’t try to remove data from an empty buffer.

While it may sound like a simple problem, the solution is not as easy. Not even simple. There are many sub-impediments you have to watch:

  • Locking / unlocking mechanism.
  • Multiple access to the semaphore.
  • Concurrency and mutual exclusion / race conditions.

Source: Wikipedia

 
Leave a comment

Posted by on June 17, 2015 in General

 

Tags: ,

Boxing x Unboxing

Boxing and unboxing is not to be confused with downcast / upcast.

  • Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type.
  • When the CLR boxes a value type, it wraps the value inside a System.Object and stores it on the managed heap.
  • Unboxing extracts the value type from the object.
  • Boxing is implicit
  • Unboxing is explicit.
  • The concept of boxing and unboxing underlies the C# view that a value of any type can be treated as an object.

Example:

Boxing

int i = 123;
// The following line boxes i. 
object o = i;

Unboxing

o = 123;
i = (int)o;  // unboxing

Reference: MSDN

 
Leave a comment

Posted by on June 5, 2015 in General

 

Tags: , , , ,

Observer vs Publish Subscribe (Pub Sub) Pattern

Oberserver

  • The recipient knows who’s the sender of the message.
  • Unicast, send one, receive by one.
  • Asynchronous.
  • Straight forward, from sender to recipient directly.

Pub Sub

  • Both sender and recipient don’t know who send or receive the message. They just don’t need to know.
  • Multicast approach, send one, every one receives.
  • Asynchronous, messages can be sent to multiple recipients at the same time.
  • Message queue based, there’s some kind of container to queue a message.
 
Leave a comment

Posted by on June 3, 2015 in General

 

Tags: , , ,

ASP.Net Web API Pipeline

Similar to ASP.Net MVC but not exactly the same. Pedro Felix has this self-explanatory graph depicting ASP.Net Web API

asp-net-web-api-pipeline

Head over to the full article, ASP.Net Web API Processing Architecture 

 
Leave a comment

Posted by on June 1, 2015 in General

 

Tags: ,

Upcasting x Downcasting

Upcasting

Is when you cast an object to its base class type.

public class Person
{ }

public class President : Person
{ }

void Main()
{
    var president = new President();

    // Upcasting
    var person = (Person)president;
}

Downcasting

Well, it’s the opposite of upcasting, when you cast a reference of a base class to one of its derived classes.

You can only downcast when the object’s type is original a derived class, so it’s important to perform some checking prior, such as using as or is operators.

public class Person
{ }

public class President : Person
{ }

void Main()
{
    var president = new President();
    var person = (Person)president;

    // Downcasting
    var president = (President)person;
}
 
1 Comment

Posted by on April 27, 2015 in General

 

Tags: , , ,

int.SubString() ?

How would you write a Substring function for an Integer?

 
Leave a comment

Posted by on April 16, 2015 in General

 

Tags: , ,

 
%d bloggers like this: