Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Operating System Expert

A thread is defined as an independent stream of instructions that can be scheduled to run as such by the operating system. Each program contains a number of threads which can be running in parallel.

The program  intro.c is a demonstration of using  pthread_create(thread,attr,start_routine,arg) function to create a new thread. The parameter thread is used as a way to pass variable between the main programs to the thread. The  attr parameter is used to set the thread attributes, which is usually set to NULL. The start_routine parameter is the C routine being executed when the thread starts. The arg parameter is the argument passed to the routine.

A thread is terminated using the function pthread_exit(NULL).
 
In the beginning of the main program a  thread_id of 1 is assigned to the first thread via the thread_data structure that is declared at the beginning of the program. This is used to identify which process is being run by the processor. Then the thread is created using the pthread_create() function with the rc variable which is used to identified the problem if the thread fail to be created. The first thread will execute the PrintProcess1 routine when the thread is created. After the first thread is created we create the second thread with a thread_id of 2 using the same procedure, but this time the PrintProcess2 routine will be used for the second thread.

In each of the PrintProcess routine the thread_id will be passed onto a process_id variable via the threadid data structure. Then the process will print a message saying the process is running, then delay by the number of seconds that is decided by the process_id, and display a message saying the process is finished. The pthread_exit(NULL) function will be used to terminate the current thread.

Operating System, Computer Science

  • Category:- Operating System
  • Reference No.:- M9622507

Have any Question?


Related Questions in Operating System

Question topic computerized operating systems os are almost

Question: Topic: Computerized Operating Systems (OS) are almost everywhere. We encounter them when we use out laptop or desktop computer. We use them when we use our phone or tablet. Find articles that describes the diff ...

Discussion question this research assignment will give

Discussion Question : This research assignment will give further information on the nature and workings of multi-tasking and multi-processing operating systems. All information reported in this assignment is to be in the ...

Question state the required answer precisely and then

Question : State the required answer precisely and then provide proper explanation. It is not enough to provide one- word or one-line answers. What is the purpose of the command interpreter? Why is it usually separate fr ...

Question description of lasa in this assignment you will

Question: Description of LASA: In this assignment, you will select a real-world operating system (can be for a PC, server, tablet, handheld, or embedded device). You will introduce the operating system and its components ...

Show all stepssuppose that the following processes arrive

Show all steps Suppose that the following processes arrive for execution at the times indicated. Each process will run the listed amount of time. in answering the questions, use non-preemptive scheduling and base all dec ...

Question you are a security administrator responsible for

Question: You are a security administrator responsible for providing secure configuration requirements for new laptop deployments. After reading Module 2 of Certified Secure Computer User v2exercises, apply the configura ...

Assignment -building a multi-threaded web server using c

Assignment - Building a multi-threaded web server using C and p threads, following the model from the lecture. Your program will have one thread acting as a dispatcher thread, listening fornetwork connections with reques ...

Question note apa format 250 words and three reference

Question: Note: APA format 250 words and three reference without plagarism Computerized Operating Systems (OS) are almost everywhere. We encounter them when we use out laptop or desktop computer. We use them when we use ...

Question 1answer the following questions 10 marks a

Question 1 Answer the following questions: 10 marks a. Consider the following page reference string: 3, 1, 4, 1, 2, 3, 5, 3, 2, 1, 2,5, 4, 3, 5, 2, 4,2, 5,3 Using the above page reference string display the contents of t ...

State the required answer precisely and then provide proper

State the required answer precisely and then provide proper explanation. It is not enough to provide one- word or one-line answers. Briefly describe the following concepts and indicate how they are related in the context ...

  • 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