Monday, 16 June 2014

Important Apps for your Android Phones in 2014

Posted by Suhel Sayyad

Android is the leading Smartphone OS (Operating System) around the world.  Smart Phone market is keep on increasing with fight between iOS and Android. It is also very hot topic in current generation though Android and iOS both is winner in some situations but numbers of Android phone users are more than iOS phone users (as survey by Kantar in 2014).  So today I picked up Android for you all!!!
Android phones are all over in the world and in this new generation people only look for smartphones which give them 1000’s of interactive features with tons of FREE apps.
There are nearly 1.2 million apps in the Google Play and out of theses 1 million apps are FREE.  This makes it harder to find right app for you. So here, I am going to give you some room by listing the best FREE apps in the Google play which is quite necessary to your phone or a must download app all by 2014.
I have categorized the apps so that people looking for niche apps can get it easily.
Below are the following categories present in the info-graphic shown below!!!
  • Books & References
  • Communication
  • Entertainment
  • Health
  • Media & Video
  • News
  • Personalization
  • Photography
  • Productivity
  • Shopping
  • Social
  • Tools
  • Travel
  • Weather
I hope you enjoy the info-graphic and find the best app to your phone.
Read More

Wednesday, 4 June 2014

Utility of PThread on Linux

Posted by Suhel Sayyad 6 Comments
Linux is a platform where we can run multiple threads synchronously. Thread is a part of a program and one program contains multiple threads. So we can achieve multithreading technique.

Creating a thread is similar to forking a new process. Only the difference is that, fork is shares the little bit of information of parent process and thread shares the more information with global and static local variables, open files and the process ID. For example, communication between client- server running on different computer systems can be completely specified by the association called a socket. In this client sends a request to server using connect() protocol, server response to client request using accept() protocol. After establishing a connection client-server both communicate with each other by using read and write system calls.

Utility of PThread on Linux


In above diagram it shows the creation of server and client programs. Server initiate first and then initiate more than one clients in a number.  Whenever a client connects to the server, a new thread can be created. Server can accept request of multiple clients at a time and server can create a connection ID number for each client and it provide access to the clients. So here we can achieve multi-threading concept.

PThread:-

PThread is a POSIX library which is used to creating a threads. PThreads is a set of threading interfaces. Creating and terminating threads, waiting for threads to complete, and managing the interaction between threads these actions are handle by the API. pthread.h header file includes the PThread library functions.
So, PThreads exist within a process but has its own independent control flow. Like heap and file descriptor it share common process resources. Two threads can concurrently read and write to the same shared memory. Each PThread maintains its own stack pointer, private set of registers, and can block and wake up on its own set of signals. 
   
      The function pthread_create is used to create a new thread, and the function pthread_exit is used by a thread to terminate itself.

 Function calls for PThread-

1.pthread_create()-    

int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void*(*start_routine)   (void),(void *arg)) ;
Where
thread - returns the thread id. (unsigned long int defined in bits/pthreadtypes.h)
attr - Set to NULL if default thread attributes are used.
void * (*start_routine) - pointer to the function to be threaded. Function has a single argument:             pointer to void.
*arg - pointer to argument of function. To pass multiple arguments, send a pointer to a structure.
 

2. pthread_exit()-

 void pthread_exit(void *retval);
where,
retval - Return value of thread. Return value is passed as a pointer.

Utility of PThread on Linux

3.pthread_self:

pthread_t pthread_self()
Returns the calling thread's identifier.
The pthread_self subroutine returns the calling thread's identifier.

4.pthread_join:

int pthread_join(pthread_t thread, void **value_ptr);
Blocks the calling thread until the specified thread id terminates.

5.pthread_detach:

int pthread_detach(pthread_t thread, void **value_ptr);
Detaches the specified thread from the calling thread.
 
Utility of PThread on Linux
 

Q. How to compile a program?

We should use following statement :
              $ gcc -o < executable name > < name of source file > -lpthread
For example to compile a simple Hello World program, 
           $ gcc -o helloworld pthread-helloworld.c –lpthread

Q. How to execute a program?

      We should use following statement:
             bsub -q <queue-name> [options] ./<executable-name>

Program for Creating a Thread-

#include <pthread.h>
#include <stdio.h>
#define N 5
void* hello(void *id)
 {
printf("Hello %d\n", (long)id);
pthread_exit(NULL);
}
int main (int argc, char *argv[])
 {
pthread_t threads[N];
for(long t=0; t<N; t++)
{
int rc = pthread_create(&threads[t], NULL, hello, (void *)t);
if (rc) exit(-1);
}
pthread_exit(NULL);
}


Author: This article is written by my proud student Miss. Ashwini Khochikar. You can find her on Facebook.

Read More