Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
3Activity
0 of .
Results for:
No results containing your search query
P. 1
Lecture 23 25

Lecture 23 25

Ratings: (0)|Views: 55|Likes:
Published by api-3729920

More info:

Published by: api-3729920 on Oct 15, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

Web Design & Development
CS-506
- 277 -

Lec 23-25
HANDOUTS
WEB DESIGN AND DEVELOPMENT

Lec \u2013 23
Web Design & Development
CS-506
- 278 -
Lecture 23
Multithreading
Introduction
Multithreading is the ability to do multiple things at once with in the same application. It
provides finer granularity of concurrency. Athread \u2014 sometimes called anexecution
context or a lightweight process \u2014 is a single sequential flow of control within a
program.

Threads are light weight as compared to processes because they take fewer resources then a process. Athread is easy to create and destroy. Threads share the same address space i.e. multiple threads can share the memory variables directly, and therefore may require more complex synchronization logic to avoiddeadlocks andstarvation.

Sequential Execution vs Multithreading

Every program has atleast one thread. Programs without multithreading executes sequentially. That is, after executing one instruction the next instruction in sequence is executed. If a function is called then until the completion of the function the next instruction is not executed. Similarly if there is a loop then instructions after loop only gets executed when the loop gets completed. Consider the following java program having three loops in it.

// File ThreeLoopTest.java
public class ThreeLoopTest {
public static void main (String args[ ]) {
//first loop
for (int i=1; i<= 5; i++)
System.out.println(\u201cfirst \u201d +i);
// second loop
for (int j=1; j<= 5; j++)
System.out.println(\u201csecond \u201d + j);
// third loop
for (int k=1; k<= 5; k++)
System.out.println(\u201cthird \u201d + k);
} // end main
} // end class
Lec \u2013 23
Web Design & Development
CS-506
- 279 -
When the program executes, the loops are executed sequentially, one after the other. It
generates the following output.
Note: Each loop has 5 iterations in theThreeLoopTest program.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->