
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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).](https://content.bartleby.com/qna-images/question/5bd4c086-c49b-4218-afb2-682b6bdbe49e/f7c3a3e2-5c66-440f-b6e9-116d008b9714/u3ssz1h_thumbnail.png)
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](https://content.bartleby.com/qna-images/question/5bd4c086-c49b-4218-afb2-682b6bdbe49e/f7c3a3e2-5c66-440f-b6e9-116d008b9714/s9yphnz_thumbnail.png)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps

Knowledge Booster
Similar questions
- 1. Consider the loop from Section 8.3 of your textbook. prefixes = 'JKLMNOPQ'suffix = 'ack' for letter in prefixes: print(letter + suffix) Put this code into a Python script and run it. Notice that it prints the names "Oack" and "Qack". Modify the program so that it prints "Ouack" and "Quack" but leaves the other names the same. Include the modified Python code and the output in your submission. 2. Give at least three examples that show different features of string slices. Describe the feature illustrated by each example. Invent your own examples. Do not copy them for the textbook or any other source. The code and its output must be explained technically. The explanation can be provided before or after the code, or in the form of comments within the code. For code modification type of questions, always mention or clearly highlight the part which is modified, along with the reason stated, as a code comment. The descriptive part of your response must be at least 200 words. If you…arrow_forwardWhat does the following Python code print to the terminal? (Assume we run this as a complete snippet of code. Be precise with any delimiters like commas, parenthesis, etc.) 1st = (4, 9, 16) for i in range (len(lst)): 1st[i] = lst[i] + 1 print(lst) 4 9. 16 O 4, 9, 16 O 5 10 17 O Error. Tuples are immutablearrow_forwardQUESTION 17 If program code references an invalid array index value, when is an error message generated? a. An error occurs during execution. b. An error occurs when the program is compiled. c. No message is generated since Java provides no error checking for this problem. d. An error occurs after execution is completed.arrow_forward
- typed out explained and please make briefarrow_forwardCan someone please help me translate this to MIPS code and also screenshot compiled code on MIPS STIMULATOR. Much appreciate if you keep it short and simple. Thanksarrow_forwardHello, I am struggling with getting this DICE GAME to function properly. I have made an attempt to try and get the overall program to debug and run without errors, but to no avail. If I can get some help getting my PYTHON program to Run Correctly. #Lab 7-3 The Dice Game #add libraries needed playerTwo = 'NO NAME' playerOne = 'NO NAME' inputNames = ("enter name") import random #the main function def main(): print #initialize variables endProgram = "no" playerOne = "NO NAME" playerTwo = "NO NAME" #call to inputNames playerOne, playerTwo = inputNames(playerOne, playerTwo) #while loop to run program again while "endProgram" == 'no': #initialize variables p1number = 0 p2number = 0 winnerName = 'NO NAME' #call to rollDice winnerName = "rollDice"(p1number, p2number, playerOne, playerTwo, winnerName) #call to displayInfo displayInfo: ("winnerName") #end of while loop endProgram = "raw_input"('Do you want to end program?(Enter yes…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education