[go: up one dir, main page]

0% found this document useful (0 votes)
31 views15 pages

Thread On Linux

The document discusses threads on Linux operating systems. It covers types of threads, how to create threads in Linux using header files and functions like pthread_create, and provides an example code. It also discusses thread pools and terminating threads. The document contains information about threading in Linux kernels over time.

Uploaded by

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

Thread On Linux

The document discusses threads on Linux operating systems. It covers types of threads, how to create threads in Linux using header files and functions like pthread_create, and provides an example code. It also discusses thread pools and terminating threads. The document contains information about threading in Linux kernels over time.

Uploaded by

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

THREAD ON LINUX

OPERATING SYSTEM
Group 4

11:11PM
enda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agen

Members of the group

Dinah Aryani Zavitri


(2220010111)

Karyn Fernanda Yulius


Group 4 (2220010126)

Septia Anggraini Nurfakih


(2220010165)
Thread Creating
The Kernel Linux

THREAD ON
Thread on Linux
LINUX
Types of Thread
At the time of its
release, Linux had no
threading built into
its kernel. However,
Linux supports entity
Background
processes which can
MAP CONCEPT be scheduled using
the clone system call.
But now Linux
supports process
cloning using the
Clone() and fork
system calls.
Thread
n Header • Section Header • Section Header • Section Header • Section Header • Section Header • Section Header • Section H

Thread

A thread is a flow of
execution through the
process code.

Back to Agenda Page

n Header • Section Header • Section Header • Section Header • Section Header • Section Header • Section Header • Section H
on the featured statistic • Elaborate on the featured statistic • Elaborate on the featured statistic • Elaborate on the featu

Types of Thread

on the featured statistic • Elaborate on the featured statistic • Elaborate on the featured statistic • Elaborate on the featur
Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda • Agenda

Multithreading is a programming technique that


allows multiple subthreads program
processes can run in parallel
Multi-Thread
One to One Model
Model
Many to Many Models
Many to One Model
Terminating a thread before it
Cancellation completes is called cancellation the
thread. For example, if multiple
threads search a database at the
same time and one thread returns
results, the remaining threads may
be killed
In computer programming, a
thread pool is a software design
Thread pool pattern for achieving
concurrency in computer
programs.

Back to Agenda Page


Thread on The Linux Thread project uses this system call

Linux to simulate user space threads. Unfortunately, this


approach has several drawbacks, particularly in the
areas of signal processing primitives, scheduling,
and
synchronization between processes. Increasing
Linux's threadability requires kernel support and
rewriting of the threads library. Two competing
projects responded to this challenge.

At the time of its release, Linux had no


threading built into its kernel..
Thread Creating
Header files that often used to create a
thread:
To create threads on Linux, we need the 1. stdio.h : Standard input output in the
following tools and materials: terminal.
1. The Linux operating system already 2. string.h : String manipulation
supports threads 3. pthread.h : Functions for thread
2. GCC (GNU C Compiler), already installed creation and thread management
in the Linux distro. (must have)
4. stdlib.h : Standard library in C which
3. Text Editor, used to write our program's C
contains standard functions of a
code.
program
5. unistd.h : Contains constants and
additional types
Example on Thread Linux
if(pthread_equal(id,tid[0])) {
Following brief steps to create a simple thread on linux:
printf("\n First thread processing\n");
1.) Make sure that the include and id of the thread are included in
}
the code
#include<stdio.h>
else {
#include<string.h> printf("\n Second thread processing\n");
#include<pthread.h> }
#include<stdlib.h>
#include<unistd.h> for(i=0; i<(0xFFFFFFFF);i++);
pthread_t tid[2];
Note pthread_tid is to create a thread id return NULL;
2.) Create a thread at the core of the program (int main) using the }
pthread_create function Note: this function corresponds to step 2. This function is
pthread_create (& (tid [i]), NULL, & doSomeThing, NULL); passed to pthread_create
Note: 4) If you want between threads to know each other (one thread
● tid [i] is the thread id created in step 1 knows there is another thread, so that the process does not get
● do Some Thing is a function executed by a thread an error) use the pthread_join function
3.) Make sure the thread has a function that is performed pthread_join(th1, NULL);
void* doSomeThing(void *arg) { pthread_join(th2, NULL);
unsigned long i = 0; Note: For example, if there are two threads named th1 and th2
pthread_t id = pthread_self(); that will be joined.
In symetric multiprocessing, multiple processors
SMP share a common memory and operating system. All
( Symetric these processors work together to execute processes.
Multiprosesing)
The kernel initially contained thousands of lines
of code, went through several versions, and
The Kernel eventually reached millions of lines. As open
Linux source software, accessible to anyone on the
Internet at any time.
Conclusion
Threads are divided into types, Single Thread and Multi-threaded.
User-Level threads are threads which are seen to the programmer and
aren't diagnosed through the kernel. User-Level threads are usually
managed. In general, thread-level users are quicker to create and
preserve than kernel threads.

Back to Agenda Page


Thank you!
For your attention :D

You might also like