Chapter 4 operating systems

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

what is a thread?

A thread is the smallest unit of processing that can be performed in an OS. In most modern operating systems, a thread exists within a process - that is, a single process may contain multiple threads

Which of the following components of program state are shared across threads in a multithreading process? A. Register values B. Heap memory C. Global variable D. Stack memory

B. Heap memory and global variables shared across in multi-thread process. In multi-thread process, each thread has its own stack and register values.

Why are a number of threads used in executing any application program?

Because if any single thread is blocked, the application will not stop. Most of the programming languages use the concept of multi-threading.

Is it possible to have concurrency but not parallelism? Explain.

Concurrency but not parallelism: Both are a form of an operating system. Sometimes, to complete a task, both methods needed to finish the task and sometimes one. The priority to select, which form is better, depends upon the requirement of system and according to that operating system coding created. Yes, it is possible to have concurrency but not parallelism.

What is concurrency?

Concurrency means where two different tasks or threads start working together in an overlapped time period, however, it does not that they run at same instant.

Literal example of parallelism

Consider a scenario, where Process 'A' and 'B' and each have four different tasks p1-4, so both process go for simultaneous execution and each works independently.

Give a literal example of concurrency.

Consider a scenario, where Process 'A' and 'B' each have four different tasks P1, P2, P3, and P4. So in order for execution, first process 'A' of P1 executes, then process 'B' of P1 executes, then A and B of P2 etc... and so on and so forth

Example of circumstance where kernel thread is better than user thread?

For example, a process P1 has 2 kernel level threads and process p2 has 2 user level threads. If one thread in P1 gets blocked, its sexond thread is not affected. But in the case of P2 if one thread is blocked (say for I/O), the whole process P2 along with the second thread gets blocked.

A system with two dual-core processors has four processors available for scheduling. A CPU-intensive application is running on this system. All input is performed at program start-up, when a single file must be opened. Similarly, all output is performed just before the program terminates, when the program results must be written to a single file. between startup and termination, the program is entirely CPU-bound. Your task is to improve the performance of this application by multithreading it. The application runs on a system that uses the one-to-one threading model (each user thread maps to a kernel thread). How many threads will you create for the CPU-intensive portion of the application?

Four threads are created to perform the CPU intensive portion of the application. It is because, there should be as many threads as there are processing cores. >4, wouldn't run. <4, waste of processing resources to use fewer than 4

Under what circumstances is one type of thread better than the other? (kernel better than user)

If the kernel is single-threaded, then kernel-level threads are better than user-level threads, because any user-level thread performing a blocking system call will cause the entire process to block, even if the other threads are available to run with the application.

Under what circumstances is one type of thread better than the other? (user better than kernel)

If the kernel is time shared, then user-level threads are better than kernel level threads, because in time shared systems context switching takes place frequently. Context switching between kernel level threads has high overhead, almost the same as a process whereas context switching between user level threads has almost no overhead as compared to kernel level threads.

Under what circumstances does a multithreaded solution using multiple kernel threads provide better performance than a single-threaded solution on a single-processor system?

In a single-processor system, the multithreaded solution uses the multiple kernels than a single-threaded solution for a better performance because of the following scenarios: In a single-processor system, when the system suffers a page fault the kernel thread switches into another kernel thread while running the process. It leaves the time in a useful manner. Also, for the single-threaded solutions, when the page fault occurs, it is not capable to perform the process on the useful note in the system. It leads to the waiting time and suffers the events in the process of the system.

Provide two programming examples in which multithreading does not provide better performance than a single-threaded solution

In a web server environment, a number of users request for the application. Thus, when any application is executed through the web server, a number of different threads are executed for different users. In GUI, different threads are executed for different tasks. For example, first thread is used to fix the bugs, the second thread is responsible for the execution of the program, and another one is responsible for the performance of the program.

Assume that an operating system maps user-level threads to the kernel using the many-to-many model and that the mapping is done through LWP's. Furthermore, the system allows developers to create real-time threads for use in real-time system.s Is it necessary to bind a real-time thread to an LWP? Explain.

In an application which is based on real time processing, time plays an important role for execution. Threads are the parts of the process and also known as light weight processes (LWP) When a thread is noticeable as a thread of real time but a lightweight process is not bounded with this thread, then, the thread must have to be waiting for the attachment of LWP. When an LWP is attached to any thread, the priority of that thread becomes higher. So, in a condition of dead lock, if a thread is having LWP, the thread has a minimum waiting time for the execution and time is saved. Thus, it can be said that the LWP attached thread is required in the real time systems.

What is multithreading?

In computer architecture, multithreading is the ability of a central processing unit (CPU) (or a single core in a multi-core processor) to execute multiple processes or threads concurrently, supported by the operating system.

Provide two programming examples in which multithreading does provide better performance than a single-threaded solution

In linear programming, the multithreading does not provide better performance than a single-threaded solution. In the single-threaded solution, the linear programming has better performance. Programs like, computer the factorial of a number, sorting numbers, and minimizing the linear equations provide better performance using the single thread. The multithreading does not provide better performance in the shell programs. The shell programs use the single thread to execute the program. C shell and korn shell programs do not provide better in multithreading.

In a multiprocessor environment, which thread is better

Kernel level threads are better than user level threads because kernel level threads can run on different processors simultaneously while user level threads of a process will run on one processor only even if multiple processors are available.

For scheduling purposes, some OS assigns the user-level threads to the

Kernel threads

what are the pros of the way Linux views threads and processes?

Linux consider these as similar, so codes belong to OS can be cut down easily. Scheduler present in the Linux OS do not need special code to test threads coupled with each processes. It considers different threads and processes as a single task during the time of scheduling.

It is much more complicated for the single-threaded solution to achieve the efficiency achieved by the

Multi threaded solution

Example of parallelism

Multi-cored processor

Give an example of concurrency.

Multi-task switch on a single-cored processor In a concurrency, minimum two threads are to be executed for processing. A more generalized form of parallelism includes time-slicing which is a form of virtual parallelism.

Which is more efficient- single processor systems multiprocessor systems?

Multiprocessor systems

Can Linux understand both threads and processes?

No, it considers both threads and processes as tasks. It cannot distinguish between them.

The figure at 4.16: what would be the output from the program at Line C and line P?

Output at Line C: The output is CHILD: value = 5. The child process in the thread is forked by parent process; the parent process and child process each have its own memory space. After forking, the parent process waits for the completion of child process. New thread is created for child process and the runner() funtion is called which set the value of the global variable to 5. Thus, after execution of this line, the value displayed will be 5. Output at Line P: The output is PARENT: value = 0. After completing the child process, the value of the global variable present in the parent process remains 0. Thus, it will remain zero and print 0.

What is the default thread cancellation type?

PTHREAD_CANCEL_DISABLE

What are the two states in thread cancellation?

PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_ENABLE

What is parallelism?

Parallelism is where two or more differnt tasks start their execution at the same time. it means that the two tasks start working simultaneously

Two programming examples for the better performance is as follows?

Sequential programs are not good for candidates for multi programming. Calculating individual tax returns is one of the examples for this type of program. The second example can be any shell programs like C-shell or Korn shell. These programs monitor its own working places such as open files, current working directory, and environment

Consider a multicore system and a multithreaded program written using the many-to-many threading model. Let the number of user-level threads in the program be greater than the number of processing cores in the system. Discuss the performance implications of the following scenarios: The number of kernel threads allocated to the program is equal to the number of processing cores.

The scheduler in the system can schedule only one kernel thread at a time to one user level process. Since the system is many to many threading model, many user level processes and kernel threads will be idle. The number of processors is equal to the kernel threads; hence, all the user level processors run concurrently in the kernel threads assuming all kernel threads are free and none of them are blocked.

Consider a multicore system and a multithreaded program written using the many-to-many threading model. Let the number of user-level threads in the program be greater than the number of processing cores in the system. Discuss the performance implications of the following scenarios: The number of kernel threads allocated to the program is greater than the number of processing cores but less than the number of user-level threads.

The scheduler in the system can schedule only one kernel thread at a time to one user level process. Since the system is many to many threading model, many user level processes and kernel threads will be idle. The number of processors is less than the kernel threads, processes can be mapped to kernel threads which is available and can be access quickly. If a kernel thread is busy, the user level processes will be swapped with kernel threads which are idle.

Consider a multicore system and a multithreaded program written using the many-to-many threading model. Let the number of user-level threads in the program be greater than the number of processing cores in the system. Discuss the performance implications of the following scenarios: The number of kernel threads allocated to the program is less than the number of processing cores.

The scheduler in the system can schedule only one kernel thread at a time to one user level process. Since the system is many to many threading model, many user level processes and kernel threads will be idle. The number of processors is greater than the kernel threads, processes can be mapped to kernel threads which is available and can be accessed quickly. most of the processors will not be utilized and they will be idle.

Consider the following code segment: pid_t pif; pid = fork(); if (pid==0) { /* child process */} fork(); thread_create(...); } fork(); How many unique processes are created here?

The statement pid = fork(); before the if statement creates one process. The parent process p0 creates this process. let it be p1. The statement fork(); in the if statement creates one process. The parent process p1 creates this process. let it be p2 After the if statement, parent process p0, process p1, and process p2 will execute fork(); creating three new processes. One process is created by parent process p0. One is created by p1, and one by p2. Let the three new processes created by p0, p1, and p2 are p4, p5, and p6. Therefore, 6 unique processes created.

What is data parallelism?

The subset of same data is allocated across the multiple computing cores and each core operates same operation on those data.

What two points are known as cancellation points? What function is used to create them?

The system test for pending cancellation requests in certain blocking functions, if cancellation function is ENABLED and its type is DEFERRED. These points are known as cancellation points. pthread_testcancel() function is used to create cancellation points.

What is task parallelism?

The task or thread is allocate across the multiple computing cores and each core operates same operation of those data.

What do thread cancellation state and type determine with regards to cancellation?

They determine when the thread cancellation request is placed.

What are the cons of the way Linux views threads and processes?

This ability makes it harder for the Linux OS to inflict process-wide resource limitations directly. Extra steps are needed to recognize that each process belongs to appropriate threads and complexity in performing relevant tasks.

What is thread cancellation? What does it lead to?

Thread cancellation is a process of cancelling thread before its completion. Thread cancellation leads to termination of the executing thread in process.

A system with two dual-core processors has four processors available for scheduling. A CPU-intensive application is running on this system. All input is performed at program start-up, when a single file must be opened. Similarly, all output is performed just before the program terminates, when the program results must be written to a single file. between startup and termination, the program is entirely CPU-bound. Your task is to improve the performance of this application by multithreading it. The application runs on a system that uses the one-to-one threading model (each user thread maps to a kernel thread). How many threads will you create to perform the input and output? Explain.

Thread count depends upon the priority and requirements of the application. So only thread is enough for this kind of application and this thread is going to handle both input and output operation. It only makes sense here to create as many threads as there are blocking-system calls, as the threads will be spent blocking. There are no benefits in creating additional threads.

pid_t pif; pid = fork(); if (pid==0) { /* child process */} fork(); thread_create(...); } fork(); How many unique threads are created?

Thread creation is done in if block by the function pthread_create(). Only child process p1 is executed in the if block. Therefore, process p1 will create one thread. In the if block one process p2 is created using the fork(). Therefore, process p2 will also create a thread. Hence, the number of unique threads created are 2.

What are two differences between user-level threads and kernel-level threads?

User-level threads: The existence of user-level threads is unknown to the kernel. Kernel-level threads: The existence of kernel-level threads is known to the kernel. User level threads: are managed without kernel support. Kernel level threads: are managed by the OS. User level threads: are faster to create than kernel level threads. Kernel level threads: are slower to create. User level threads: are scheduled by the thread library Kernel level threads: are scheduled by the kernel.

describe the actions taken by a kernel to context-switch between kernel-level threads. What happens to the context stored in the registers of the CPU?

When a context switch is occurring among the threads of kernel level, the kernel suspends all the threads and their respective values from the registers of the CPU. The newly scheduled threads restore the values in the registers. Thus, due to this, the current process state is also saved as well as the state of the incoming processes can also be restored. For a kernel, the execution time is the main issue. If the new processes are created for the execution, rather than threads, it becomes more time consuming. So, the context stored in the registers of the CPU is switched.

Can windows understand both threads and processes?

Windows OS understands threads and processes as different.

So in all, is it possible to have concurrency but not parallelism?

Yes

What resources are used when a thread is created? How do they differ from those used when a process is created?

creating either a user or kernel thread involves allocating a small data structure to hold a thread ID, a program counter, a register set, stack and priority, whereas creating a process involves allocating a large data structure called a PCB (process control block) which includes a memory map, list of open files, and environment variables. Allocating an managing the memory map is typically the most time consuming activity.

Can a multithreaded solution using multiple user-level threads achieve better performance on a multiprocessor system than on a single-processor system?

in multithreading, there are multiple user-level threads running simultaneously doing different tasks. The operating system assigns the multiple user level threads to different kernel level processes for the purposes of scheduling the tasks.

Is the user schedules the process in the kernel threads, if one kernel thread is blocked? it ___-

it automatically switches to the other.

Describe the dependency of threads and processes.

processes act independently while threads always remain dependent on their consequent thread for their execution. Threads remain a chain of instructions where a small breakdown may terminate the entire execution.

What function is used to cancel a thread?

pthread_cancel()

It is efficient for the system to schedule user level processes to

the kernel threads


Set pelajaran terkait

Chapter 3 Address Resolution Protocol

View Set

legal social exam 1, law chapter 7, Bus 250- Unit 1, Ch. 7, Business Law - Chapter 8, Business Law Homework Review, Blaw 5.2, Blaw 5.1, Chapter 4: MindTap Worksheets, Chapter 6: Homework, blaw 6.3, blaw 6.2 trial, blaw 6.1 litigation, Worksheet 6.1:...

View Set

The belmont report principles and applications C4

View Set

Intentional Interviewing: Chapter 6—Encouraging, Paraphrasing, and Summarizing: Key Skills of Active Listening

View Set

Chap 7 : The International Monetary System and the Balance of Payments

View Set

Quiz: Administering a Large-Volume Cleansing Enema

View Set