answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vaieri [72.5K]
2 years ago
15

Suppose two threads execute the following C code concurrently, accessing shared variables a, b, and c: Initialization int a = 4;

int b = 0; int c = 0; Thread 1 Thread 2 if (a < 0) { b = 10; c = b-a; a = -3; } else { c = b + a; } What is the total number of possible values for c after both threads complete? You can assume that reads and writes of the variables are atomic and that the order of statements within each thread is preserved in the code generated by the C compiler?
Computers and Technology
1 answer:
Oksanka [162]2 years ago
6 0

Answer:

Therefore, there are 4 possible values for c after both threads complete

c = 4, 14, 3, 13

Explanation:

Initialization:

int a = 4;

int b = 0;

int c = 0;

Thread 1:

if (a < 0)

{

c = b - a;

}

else

{ c = b + a; }

Thread 2:

b = 10;

a = -3;

We have to consider all the possible cases.

Case 1: a = 4, b = 0, c = 0

if (a < 0) false

{

c = b - a;

}

else

{ c = b + a; }  c = 0 + 4 = 4

c = 4

Case 2: a = 4, b = 10, c = 0

if (a < 0) false

{

c = b - a;

}

else

{ c = b + a; }  c = 10 + 4 = 14

c = 14

Case 3: a = -3, b = 0, c = 0

if (a < 0) true

{

c = b - a; c = 0 - (-3) = 3

}

else

{ c = b + a; }  

c = 3

Case 4: a = -3, b = 10, c = 0

if (a < 0) true

{

c = b - a; c = 10 - (-3) = 13

}

else

{ c = b + a; }  

c = 13

Therefore, there are 4 possible values for c after both threads complete

c = 4, 14, 3, 13

You might be interested in
HELP ASAP U GET BRAINLIEST
Korolek [52]
B) <span>tool bar

i hope helped ^-^</span>
7 0
1 year ago
Read 2 more answers
#Write a function called string_finder. string_finder should #take two parameters: a target string and a search string. #The fun
adoni [48]

Answer:

I am writing a Python program:

def string_finder(target,search): #function that takes two parameters i.e. target string and a search string

   position=(target.find(search))# returns lowest index of search if it is found in target string

   if position==0: # if value of position is 0 means lowers index

       return "Beginning" #the search string in the beginning of target string

   elif position== len(target) - len(search): #if position is equal to the difference between lengths of the target and search strings

       return "End" # returns end

   elif position > 0 and position < len(target) -1: #if value of position is greater than 0 and it is less than length of target -1

       return "Middle" #returns middle        

   else: #if none of above conditions is true return not found

       return "not found"

#you can add an elif condition instead of else for not found condition as:

#elif position==-1    

#returns "not found"

#tests the data for the following cases      

print(string_finder("Georgia Tech", "Georgia"))

print(string_finder("Georgia Tech", "gia"))

print(string_finder("Georgia Tech", "Tech"))

print(string_finder("Georgia Tech", "Idaho"))

Explanation:

The program can also be written in by using string methods.

def string_finder(target,search):  #method definition that takes target string and string to be searched

       if target.startswith(search):  #startswith() method scans the target string and checks if the (substring) search is present at the start of target string

           return "Beginning"  #if above condition it true return Beginning

       elif target.endswith(search):  #endswith() method scans the target string and checks if the (substring) search is present at the end of target string

           return "End" #if above elif condition it true return End

       elif target.find(search) != -1:  #find method returns -1 if the search string is not in target string so if find method does not return -1 then it means that the search string is within the target string and two above conditions evaluated to false so search string must be in the middle of target string

           return "Middle"  #if above elif condition it true return End

       else:  #if none of the above conditions is true then returns Not Found

           return "Not Found"

6 0
1 year ago
+10 points~~~Which option is used in emails to inform the recipient that they should exercise discretion in accordance with shar
Alexxx [7]

Answer:

Sensitivity Levels

Explanation:

Sensitivity Level is option use in email to inform the recipient that they should exercise discretion in accordance with sharing the content of the message.

8 0
2 years ago
Row array gameScores contains all player scores. Construct a row array highScores than contains all player scores greater than m
Sever21 [200]

Answer:

The solution is written using Python as it has a simple syntax.

  1. def getHighScores(gameScores, minScore):
  2.    meetsThreshold = []
  3.    for score in gameScores:
  4.        if(score > minScore):
  5.            meetsThreshold.append(score)
  6.    return meetsThreshold
  7. gameScores = [2, 5, 7, 6, 1, 9, 1]
  8. minScore = 5
  9. highScores = getHighScores(gameScores, minScore)
  10. print(highScores)

Explanation:

Line 1-8

  • Create a function and name it as <em>getHighScores</em> which accepts two values, <em>gameScores</em> and <em>minScore</em>. (Line 1)
  • Create an empty list/array and assign it to variable <em>meetsThreshold</em>. (Line 2)
  • Create a for loop to iterate through each of the score in the <em>gameScores</em> (Line 4)
  • Set a condition if the current score is bigger than the <em>minScore</em>, add the score into the <em>meetsThreshold</em> list (Line 5-6)
  • Return <em>meetsThreshold</em> list as the output

Line 11-12

  • create a random list of <em>gameScores</em> (Line 11)
  • Set the minimum score to 5 (Line 12)

Line 13-14

  • Call the function <em>getHighScores()</em> and pass the<em> gameScores</em> and <em>minScore </em>as the arguments. The codes within the function <em>getHighScores()</em>  will run and return the <em>meetsThreshold </em>list and assign it to <em>highScores.</em> (Line 13)
  • Display <em>highScores</em> using built-in function print().
8 0
1 year ago
All the employees of Delta Corporation are unable to access the files stored in the server. What do you think is the reason behi
CaHeK987 [17]
C serve crash hope this is correct
5 0
1 year ago
Other questions:
  • A BCD code is being transmitted to a remote receiver. The bits are A3, A2, A1, and A0, with A3as the MSB. The receiver circuitry
    8·1 answer
  • How did josh norman and mike keller provide coverage of katrina?
    9·2 answers
  • In cell B16, enter a function to calculate the total attendance for the years 2014 through 2018 using the totals in the range B1
    10·1 answer
  • Leena needs to manually update the TOC and would prefer not to change the styles in the document.
    9·2 answers
  • Given an alphabet, print all the alphabets up to and including the given alphabet.
    15·2 answers
  • Develop an sec (single error correction) code for a 16-bit data word. generate the code for the data word 0101000000111001. show
    7·2 answers
  • Let's revisit our lucky_number function. We want to change it, so that instead of printing the message, it returns the message.
    10·1 answer
  • You have an on-premises network that contains several servers. You plan to migrate all the servers to Azure. You need to recomme
    14·1 answer
  • Define a method printAll() for class PetData that prints output as follows with inputs "Fluffy", 5, and 4444. Hint: Make use of
    13·1 answer
  • When authenticating a user's password, the password supplied by the user is authenticated by comparing the ____ of the password
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!