Semaphore Concepts and Critical Section: Android | Techbirds

Hi Folks,

Today , i will discuss some very common concepts that some developers think is just a theoretical concept and feel proud to have little practical knowledge, but this is very useful if one wants to be a good biggy developer.

Semaphores are just variables of integer king that  helps code to provide lock and release mechanism  to resources that on module will use at a particular time and protecting mishandling of resources. hence called resource management.

Many are scared of implementing the same concept in other technology and thinks that technologies are different form one to another but the concepts these technologies are lying are basically same. Use Semaphores to use in your threads handling so that one thread cannot interrupt other threads.

int MYSEMAPHORE = 0;    //LOCK

// do tour stuffs

MYSEMAPHORE = 1;       //UNLOCK

between o to 1 it will not allow other threads to use resources ans is a shared variable(s).

This concept is used to handle multi-threading. Use it on Android!! too…

Critical Section:  It is basically that code part that is shared and common interface of executing a code. It is an OS concept that if one process is executing its code that definitely using the CPU, Memory resources and in the mean time some other tasks come into play that wants to execute its part then it will not lock the resources that are occupied by others and  thats why one cannot  go into its critical section until required resources are free/available for use.

Android coders does go through these challenges when APIs Transits (recently being the 18 to 19) so instead of completely relying on OS one should take care the criticality of code by himself.

WHile(UNTIL RELEASE CONDITIONS COMES TRUE)

{   if(TASK FINISHED)

RELEASE LOCK = 0;

else

RELEASE LOCK = 1;

}

Concepts seems useful if one broaden his mind to see possibilities.

Kind Regards,

Tapan Saini

(Android Developer)

813 total views, 1 views today

Share this Onfacebook-8175873twitter-4082454linkedin-5741443google-6605079