lets make thread concept little easy............!!!!

Thread 

The main reason for writing this post as I learnt a concept which is quite deeper for threads..!!
First of all what is thread...?

we will define thread first but for thread the main thing is operating system yes...!! operating system is the first thing we require for multithreading or threading .

But which type of operating system we need that is the point the born of multithreading started.
We need an operating system that would provide us a GUI platfoem not CUI platform well you all must be famalier with What is GUI and CUI . 

As we have seen in DOS and in unix we can say that if we create a file by copy cone command till that if we want to execute any other command we have to back by pressing ctrl+z so the sole meaning here is to say that we cant do concurrent executions in Cmd .

so clear the first point was that we need an operating system that would provide a GUI platform. 

Now comming back to our question what is thread for that i would like to give an example for if we started a word and gave a print command so what happens benath it first the os takes the order of our command that print 50 pages or say 20 pages so it takes the order by taking the data , address from memory it took and the port address of the printer now as we have seen after giving the print command and closing our word still the printer is working and taking out our prints ,the mechanism behing it is the virtual memory created and all these orders are given to processor by OS... that is all the address and data and one  address is added to it that is the address of the virtual address space as that data is appeared there so what does processor do is that it fetches the data from virtual address space and feeds printer taking address that  is the ready state and running for printer by feeding and making the process happen is the running state so by this the life cycle goes on...

Now we came to the point that the address space created for that command is the thread yes that is the thread it is virtual so that memory which is created at run time neither more or less and it depends on the data

So clear about what is thread.........................
.
 Thread is a virtual address space created. 

NOW often people dosent differentiate about multitasking and multiprocessing ..

First we would take multitasking suppose i opened my computer and started writing document and ended up as well gave a print command so one thread is created for it lets name thread -1 and 
process-1

Now im little bored what to do now as i kept pages for printing now i want to play song so suppose i started winap and listed song to be played and gave a command to play so process -2 and thread - 2

Now again i m bored what to do so i decided to scan my photos and i gave command to scan now would take the port address of the scanner and will start working back so process-3 and thread -3

so these were the few examples we would say is possible in the GUI platform now say if printer has finished printed printing one page will give a call so processor will feed it with another page by seeing the address of virtual adress space and the port address of the printer and the data it already has so again running state from a ready state now if happens that it dosent have any page to print and printer gives a call so microprocessor ends the process and return back and the virtual memory it has created will be destroyed so this state is called dead state .

NOW we played a song which is for 5 minutes and a printer on the other side so as soon as it will be freed by feeding the printer it will go to control the playing of song so directly from running to ready 

So basically three stages are posible 

1) ready----> run----->ready---->run (continuosly)
2) ready---->run----->wait(wait for the call if only printer is working )
3)ready----->run------>dead (as disscussed above example )


Now all the command we give in the cmd is the exe files opening in it such as copy cone , cd.. etc 

Likewise as in GUI platform we opened word winap etc these all are exe files none other than this and what is the exe files containing nothing but a program written by a programmer .. so all are the different programs opened and it is called multitasking 

NOW lets take another example if i opened a word and did some editing and gave a print command that is one program opened and many processes done at a time is called multiprocessing

THIS MULTIPROCESSING IS POSSIBLE BY US TO MAKE AS IT IS MADE BY MULTITHREADING AND MAIN ROLE IS BY THE COMPILER here we would talk about the java compiler.

MULTITASKING is not in our hands it is in the hands of OS so if we want to do anything we might be knowing assembly language ....

NOW different behaviour of threads we take here is ....

SEE as i said that in the process of printing ,it will take the address of virtual memory and also the port address of the printer and the address of the main memory of course ....

SO it has all the the data and the addresses with it so if we close the window of the word it would continue and dosent stops ..

Like wise different is the case with all the song player it only takes the address not the data the practical example is you all might have noticed that when we say that the first song is played ohhh now i dont want to play the second and third 0ne so you delete it and it will not be played this is the practical example of it .

Notice it with the word you thought ohh there is the mistake in the sentence let me edit while its geeting printed noooo it will print the false one so this is the proof that thread works by taking the data and the address 

so again we partitionate as 

1)thread which takes only the address (this is the short thread)
2)thread which takes data as well as the address .

This was all about the topic hope you all might felt unique knowledge ...!!! keep visiting...!!

Comments

Popular posts from this blog

State space search / blocks world problem by heuristic approach /TIC TAC TOE

Navigation in Vaadin.

Drag and drop items from one Grid to another