0% found this document useful (0 votes)
7 views6 pages

Thread Libraries& Threads Issues

Thread libraries are APIs provided by operating systems for creating and managing threads, which can be implemented in user space or kernel space. Widely used thread libraries include Java threads, Pthreads, and Win32 threads, each with unique features and functionalities. The document also discusses threading issues such as system calls, thread cancellation, signal handling, thread pools, and thread-specific data.

Uploaded by

maheshrepana100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Thread Libraries& Threads Issues

Thread libraries are APIs provided by operating systems for creating and managing threads, which can be implemented in user space or kernel space. Widely used thread libraries include Java threads, Pthreads, and Win32 threads, each with unique features and functionalities. The document also discusses threading issues such as system calls, thread cancellation, signal handling, thread pools, and thread-specific data.

Uploaded by

maheshrepana100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Thread Libraries

Thread Library is a thread API (Application programming Interface) which is a set of functions,
methods and routine provided by operating system for creating, managing and coordination of the
threads.

Thread Libraries may be implemented either in user space or Kernel Space Library.

 If the thread Library is implemented at a user space then the code and information of thread
Library world be reside in user Space in this scenario invoking any function from thread
Library would be simple function Call and can’t be a system call.
 But if the thread Library is implemented at the Kernel space then the code and information
of thread boy Would be reside in kernel mode space and supported by operating system, in
this scenario invoking any from thread Library would be System function Call to the kernel

There are lots of thread Libraries available, but some of them are widely used. Some of
they are
1. Java thread
2. P Thread
3. Win32thread

JAVA THREAD:
1. Thread is a primary model of program execution in Tam program and Tara Language
and It's Aps provides a rich Variety of features for the Creation and the management
of threads. As name significance that it's cook written in Java Language.
2. However in most instances the JVM (JAVA VIRTUVAL MCAHINE) is running on top of
host operating system the Java thread App typically implemented using thread
Library a variable on the host system, which signifies that an window system the java
thread implemented through WIN32API.
3. It provide built-in support for multi-threading through Java. Long thread.

PTHREAD
1. It is also known as posix thread, it's an execution model that exists independently
from a programming language as well as a parallel model.
2. P-thread Library can be implemented either at the user space or kernel space.
3. The P thread is often implemented at the UNIX, Linux and Solaris, and it is highly
portable as it code written in p thread can typically be compiled and run on different
UNIX without much modifications.
Features of P THERAD
1. Thread – ID: if it is null then no thread is returned.
2. Attribute: Attributes of Threads, if it is null then no attributes are assigned.
3. Arguments: the actual argument by default value passed during execution.
4. Return value: it is integer then it returns zero on success and value 1 on failure.
Functions of P THERAD
1. P THERAD EXIT(): Terminates the current functions
2. P THREAD KILL (): Used to send the specified thread to terminate.

Win32 thread

1. Win32 thread is a part of Windows operating system and it is also called as


Windows Thread. It is a kernel space library.
2. In this thread we can also achieve parallelism and concurrency in same
manner as in p thread.

3. Win32 thread are created with the help of createThread () function.


Window thread support Thread Local Storage (TLS) as allow each thread to
have its own unique data, and these threads can easily share data as they
declared globally.

4. They providing native and low level support for multi-threading. It means
they are tightly integrated with window OS and offer efficient creation and
thread management.
THREAD ISSUES:

Multitasking is one of the key methods, which can be applied to improve


the performance of operations. In a multithreading environment, there are many
threading-related problems.
We shall discuss in this article threading problems associated with system
calls, cancellation of threads, signal handling, thread pools, and thread-specific
data.

Threading Issues in OS
 System Call
 Thread Cancellation
 Signal Handling
 Thread Pool
 Thread Specific Data

System Call (fork (), exec ())

They are the system calls fork () and exec ().


Fork () system calls are used to create the new process.
Fork () function gives rise to an identical copy of process which initiated
fork call. The new duplication process is referred to as a child process, while the
invoker process is identified by fork (). The instruction after fork continues the
execution with both the parent process and the child process.
Fork () system call, Let us assume that one of the threads belonging
to a multi-threaded program has instigated a fork () call. Therefore, the
new process is a duplication of fork ().
If the thread calls the exec () system call. The program specified in
the parameter to exec () will replace the entire process which includes all
threads.
 Thread Cancellation

Thread cancellation is nothing but killing the thread & terminate the thread.
Thread cancellation is the task of terminating a thread before it has completed.

So, let’s take a look at an example to make sense of it. Suppose, there is a
multithreaded program whose several threads have been given the right to scan a
database for some information. The other threads however will get canceled once
one of the threads happens to return with the necessary results.

The target thread is now the thread that we want to cancel. Thread cancellation
can be done in two ways:
 Asynchronous Cancellation: The asynchronous cancellation involves only
one thread that cancels the target thread immediately.

 Deferred Cancellation: In the case of deferred cancellation, the target thread


checks itself repeatedly until it is able to cancel itself voluntarily or decide
otherwise.

Signal Handling
Signal in Linux there are several signals which are useful in order to
send notifications to the processes, depending on the problem it can handle the
threads.

Generally signal is used in Linux systems to notify a process that a


particular event has occurred. A signal received either synchronously or
asynchronously based on the source of the reason for the event being singled.
Example:1. If the kernel wants to kill a process then it sends sigkill
(signal kill) message, so that process will be kill.
A kernel may send interrupt message to the corresponding process.
Suppose the signal will be delivered to:
 Every line of this process.
 Some special thread of a process.
 thread to which it applies

THREAD POOL:
Collection of threads can be called as a thread pool.

Client Sends request to Web Server, Webserver request the to handle the
responsibilities of Clint request threads.
It allocates a request to a thread how it is the responsibility of T1 to handle that
requests it will message one more run then it is the responsibility of T2, T3
….Tn In order to handle the Web Sever. Needs to create one lakh threads. So it
is a burden of the web server by the time pool consists of 1 lakh threads. So that
it can assign all the responsibilities of client request assign to existing 1 lakh
threads.

THREAD SPECIFIC DATA

A process will have multiple threads.


So multiple threads can share with one another with the help of data segment
which stores global variables
As well as another threads can write data into the global variables thread which
uses its own specific data.
For example, a transaction processing system can process a transaction in
individual threads for each one each transaction we perform shall be assigned
with a special identifier which in turn, shall uniquely identify that particular
transaction to us.
The system would then be in a position to distinguish every transaction
among others.

You might also like