What are thread libraries in operating system

992 views 14 slides Mar 13, 2024
Slide 1
Slide 1 of 14
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14

About This Presentation

Thread Libraries


Slide Content

OPERATING SYSTEM THREAD LIBRARIES

Thread Libraries: A thread library provides the programmer with an API for creating and managing threads. There are two primary ways of implementing a thread library.

The first is a user level library with no kernal support. All code and data structures for the library exist in user space . Invoking a function in the library results in a Local function call in user sapce and not a system call.

The second is a kernal-level library supported directly by the operating system. In this case ,code and data structures for the library exist in kernal sapce. Invoking a function in the API for the library typically results in a system call to the kernal.

There are three type of Thread libraries: POSIX thread - Pthread Win 32 thread - Windows Java Thread

The main thread libraries: POSIX thread- the library includes pthreads.h header file. The POSIX thread provided as either a user level or a kernal level library. Win 32 library -is similar to pthread library. To create s thread using the Win 32 library alwaya include windows.h header file in the program. The windows library is a kernal level library available on windows system JAVA thread - The java thread API allows threads to be created and managed directly as JAVA programs.

Pthreads: The POSIX standard defines the specification for pthreads,not the implementation. pThreads are available on Solaris,Linux,Unix,Mac OSX ,and via public domain shareware for Windows. Global variables are share among all thread.

One thread can wait for the other to rejoin before continuing. pthreads begin execution in a specified function,in this example the runner()function. pthread.h is the header file used in C language

Syntax : #inculde<pthread.h> intpthread_create(pthread_t*thread_id, const pthread_attr_t*attribute, void*(*routine)(void*),void*arg);

The Windows thread: The windows thread library is a kernal-level library available on windows systems. Many function similar to pthread. The header file is windows.h

create_Thread()-to create thread. Attributes are similar to pthread along with, security,stack size,flag to indicate current state. if flag=0,then SUSPENDED

Java Thread: The java virtual machine JVM runs on the top of the host operating system. In the Windows operating system,the java threads are implemented using Pthread. In LINUX and UNIX, the java thread is implemented using Pthread library.

In a java program, there is at least one thread of control. there are two methode to creating a thread in java program.

1. Thread class and override it’s run() method. 2. Define a class and implement a Runnable interface to it, the second method is the most common method to be used.