Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

First, remember that different processes keep their own data in distinct address spaces. Threads, on the other hand, explicitly share their entire address space with one another. Although this can make things a lot faster, it comes with the cost of making programming a lot more complicated.

In Unix/POSIX, the threads API is composed of two main calls:


pthread create(), which starts a separate thread;


pthread join(), which waits for a thread to complete.

Notice that the general syntax for using these is:

pid = pthread_create(&tid, NULL, function_ptr, argument);

pthread_join(tid, &result);

Example:
void *run(void *d)
{
int q = ((int) d);
int v = 0;
for (int i=0; iv = v + some_expensive_function_call();
return (void *) v;
}
int main()

{
pthread_t t1, t2;
int *r1, *r2;
int arg1=100;
int arg2=666;
pthread_create(&t1, NULL, run, &arg1);
pthread_create(&t2, NULL, run, &arg2);
pthread_join(t1, (void **) &r1);
pthread_join(t2, (void **) &r2);
cout << "r1= " << *r1 << ", r2=" << *r2 << endl;
}
Notice that the above threads maintain different stacks and different sets of registers; except for those, however, they share all their address spaces. Also notice that if you were to run this code in a 2 core machine, it would be expected that it ran roughly twice as fast as it would in a single core machine. If you ran it in a 4 core machine, however, it would run as fast as in the 2 core machine, since there would be no suf?cient threads to exploit the available parallelism.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9527881

Have any Question?


Related Questions in Computer Engineering

The formulas a rarr b and c and a rarr b and a rarr c are

The formulas A → (B ∧ C) and (A → B) ∧ (A → C) are logically equivalent. For this problem, you are going to prove that they are equivalent in two different ways. Prove that A → (B ∧ C) ≡ (A → B) ∧ (A → C) by writing two ...

Risky business how can us companies protect their digital

Risky Business: How Can U.S. Companies Protect their Digital Assets Overseas? Prepare a 3 to 5 paragraph briefing statement that can be used to answer the above question. Your audience will be attendees at a conference f ...

Systems analysis project 5can you answer the 4questions

Systems Analysis project 5: Can you answer the 4questions please. Personal Trainer, Inc. owns and operates fitness centers in a dozen Midwestern cities. The centers have done well, and the company is planning an internat ...

Question hypothetically speaking you are assigned to a

Question: Hypothetically speaking, you are assigned to a committee of three to decide on a dress code for Campbellsville University Staff and Faculty. Only two of the three votes are required to pass this policy. In this ...

Suppose youve designed a mips processor implementation in

Suppose you've designed a MIPS processor implementation in which the stages take the following lengths of time: IF=20ns, ID=10ns, EX=20ns, MEM=35ns, WB=10ns. What is the minimum clock period for which your processor func ...

Question you are to write a report on the malware assigned

Question: You are to write a report on the malware assigned to you in the "Week 6 Malware assignment by individual student" document. Your report, written in Microsoft Word with 12 point type and 1 in margins, must have ...

Program in cit is often times advantageous to be able to

*Program in C* It is often times advantageous to be able to transfer data between two arrays. Need a help with program (transfer.c) that add a range (by start index and end index) of numbers from array #1 to array #2 at ...

One of the assays your laboratory carries out requires a 2n

One of the assays your laboratory carries out requires a 2N HCl. You have a stock bottle of concentrated HCl with a specific gravity of 1.18 and purity of 36%. What volume of the concentrated HCl is required to make 250m ...

Suppose that you have a singly-linked list l containing the

Suppose that you have a singly-linked list L containing the sequence of numbers (1,2,3,4,5,6,7,8,9). Suppose further that you have an initially empty stack S. i) Give a pseudo-code description of a method that uses only ...

Question based upon your company profile install and

Question: Based upon your company profile, install and configure Windows Server within the virtual environment. 1. Ensure that the server name is appropriate for your corporation. 2. Create a complex password for the Adm ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As