Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question
Question 4
a) Explain, with an example, how the use of multithreading enables a program to run faster.
Use pseudocode or actual code to illustrate your answer.
b) The following is non-concurrent code for working out the cosine of a sequence of
integers. Rewrite this in Python so that it is concurrent. Your program must return the
results in the order of the input sequence. This code is available with this TCA as Q4.zip.
import math
values = [12,20,4,100,64,77,200,9,10]
def mycosine (n) :
woonwww.
return math.cos(n)
ww
wwwwwwww
def non concurrent cosines():
wwwww
for val in values:
wwwww
res = mycosine (val)
wwwww
print('Cosine of %s is %s' % (val,res), '\n')
non concurrent cosines ()
wwwwww
c) Use Python's datetime function to time the execution of the concurrent code, and to print
out the result. Add the lines of code that support this to your solution to Question 4 (b).
expand button
Transcribed Image Text:Question 4 a) Explain, with an example, how the use of multithreading enables a program to run faster. Use pseudocode or actual code to illustrate your answer. b) The following is non-concurrent code for working out the cosine of a sequence of integers. Rewrite this in Python so that it is concurrent. Your program must return the results in the order of the input sequence. This code is available with this TCA as Q4.zip. import math values = [12,20,4,100,64,77,200,9,10] def mycosine (n) : woonwww. return math.cos(n) ww wwwwwwww def non concurrent cosines(): wwwww for val in values: wwwww res = mycosine (val) wwwww print('Cosine of %s is %s' % (val,res), '\n') non concurrent cosines () wwwwww c) Use Python's datetime function to time the execution of the concurrent code, and to print out the result. Add the lines of code that support this to your solution to Question 4 (b).
1 import math
2
3 values = [12,20,4,100,64,77,200,9,10]
4
5 def cosine(n):
6
67
7
V
return math.cos(n)
8 ✓ def non_concurrent_cosines():
v
9 v
10
11
12
for val in values:
res = cosine(val)
print('Cosine of %s is %s' % (val, res), '\n')
13 non_concurrent_cosines()
14
expand button
Transcribed Image Text:1 import math 2 3 values = [12,20,4,100,64,77,200,9,10] 4 5 def cosine(n): 6 67 7 V return math.cos(n) 8 ✓ def non_concurrent_cosines(): v 9 v 10 11 12 for val in values: res = cosine(val) print('Cosine of %s is %s' % (val, res), '\n') 13 non_concurrent_cosines() 14
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education