This third part of Linux internals talks about Thread programming and using various synchronization mechanisms like mutex and semaphores. These constructs helps users to write efficient programs in Linux environment
The second part of Linux Internals covers system calls, process subsystem and inter process communication mechanisms. Understanding these services provided by Linux are essential for embedded systems engineer.
Linux has become integral part of Embedded systems. This three part presentation gives deeper perspective of Linux from system programming perspective. Stating with basics of Linux it goes on till advanced aspects like thread and IPC programming.
Linux has become integral part of Embedded systems. This presentation gives deeper perspective of Linux from system programming perspective. Stating with basics of Linux it goes on till advanced aspects like system calls, process subsystem, inter process communication mechanisms, thread and various synchronization mechanisms like mutex and semaphores. Understanding these services provided by Linux are essential for embedded systems engineer. These constructs helps users to write efficient programs in Linux environment
An unique module combining various previous modules you have learnt by combing Linux administration, Hardware knowledge, Linux as OS, C/Computer programming areas. This is a complete module on Embedded OS, as of now no books are written on this with such practical aspects. Here is a consolidated material to get real hands-on perspective about building custom Embedded Linux distribution in ARM.
In order to understand HAL layers of Android Framework, having Linux device driver knowledge is important. Hence Day-2 of the workshop focuses on the same.
This course gets you started with writing device drivers in Linux by providing real time hardware exposure. Equip you with real-time tools, debugging techniques and industry usage in a hands-on manner. Dedicated hardware by Emertxe's device driver learning kit. Special focus on character and USB device drivers.
Embedded Systems are basically Single Board Computers (SBCs) with limited and specific functional capabilities. All the components that make up a computer like the Microprocessor, Memory Unit, I/O Unit etc. are hosted on a single board. Their functionality is subject to constraints, and is embedded as a part of the complete device including the hardware, in contrast to the Desktop and Laptop computers which are essentially general purpose (Read more about what is embedded system). The software part of embedded systems used to be vendor specific instruction sets built in as firmware. However, drastic changes have been brought about in the last decade driven by the spurt in technology, and thankfully, the Moore’s Law. New, smaller, smarter, elegant but more powerful and resource hungry devices like Smart-phones, PDAs and cell-phones have forced the vendors to make a decision between hosting System Firmware or full-featured Operating Systems embedded with devices. The choice is often crucial and is decided by parameters like scope, future expansion plans, molecularity, scalability, cost etc. Most of these features being inbuilt into Operating Systems, hosting operating systems more than compensates the slightly higher cost overhead associated with them. Among various Embedded System Operating Systems like VxWorks, pSOS, QNX, Integrity, VRTX, Symbian OS, Windows CE and many other commercial and open-source varieties, Linux has exploded into the computing scene. Owing to its popularity and open source nature, Linux is evolving as an architecturally neutral OS, with reliable support for popular standards and features
The second part of Linux Internals covers system calls, process subsystem and inter process communication mechanisms. Understanding these services provided by Linux are essential for embedded systems engineer.
Linux has become integral part of Embedded systems. This three part presentation gives deeper perspective of Linux from system programming perspective. Stating with basics of Linux it goes on till advanced aspects like thread and IPC programming.
Linux has become integral part of Embedded systems. This presentation gives deeper perspective of Linux from system programming perspective. Stating with basics of Linux it goes on till advanced aspects like system calls, process subsystem, inter process communication mechanisms, thread and various synchronization mechanisms like mutex and semaphores. Understanding these services provided by Linux are essential for embedded systems engineer. These constructs helps users to write efficient programs in Linux environment
An unique module combining various previous modules you have learnt by combing Linux administration, Hardware knowledge, Linux as OS, C/Computer programming areas. This is a complete module on Embedded OS, as of now no books are written on this with such practical aspects. Here is a consolidated material to get real hands-on perspective about building custom Embedded Linux distribution in ARM.
In order to understand HAL layers of Android Framework, having Linux device driver knowledge is important. Hence Day-2 of the workshop focuses on the same.
This course gets you started with writing device drivers in Linux by providing real time hardware exposure. Equip you with real-time tools, debugging techniques and industry usage in a hands-on manner. Dedicated hardware by Emertxe's device driver learning kit. Special focus on character and USB device drivers.
Embedded Systems are basically Single Board Computers (SBCs) with limited and specific functional capabilities. All the components that make up a computer like the Microprocessor, Memory Unit, I/O Unit etc. are hosted on a single board. Their functionality is subject to constraints, and is embedded as a part of the complete device including the hardware, in contrast to the Desktop and Laptop computers which are essentially general purpose (Read more about what is embedded system). The software part of embedded systems used to be vendor specific instruction sets built in as firmware. However, drastic changes have been brought about in the last decade driven by the spurt in technology, and thankfully, the Moore’s Law. New, smaller, smarter, elegant but more powerful and resource hungry devices like Smart-phones, PDAs and cell-phones have forced the vendors to make a decision between hosting System Firmware or full-featured Operating Systems embedded with devices. The choice is often crucial and is decided by parameters like scope, future expansion plans, molecularity, scalability, cost etc. Most of these features being inbuilt into Operating Systems, hosting operating systems more than compensates the slightly higher cost overhead associated with them. Among various Embedded System Operating Systems like VxWorks, pSOS, QNX, Integrity, VRTX, Symbian OS, Windows CE and many other commercial and open-source varieties, Linux has exploded into the computing scene. Owing to its popularity and open source nature, Linux is evolving as an architecturally neutral OS, with reliable support for popular standards and features
Embedded Android System Development - Part II talks about Hardware Abstraction Layer (HAL). HAL is an interfacing layer through which Android service can place a request to device. Uses functions provided by Linux system to service the request from android framework. A C/C++ layer with purely vendor specific implementation. Packaged into modules (.so) file & loaded by Android system at appropriate time
This is the presentation I gave on Linux kernel modules at the Linux Meetup in Austin, TX, on 2/5/2015.
http://www.meetup.com/linux-85/events/185946802/
Code referred to in the presentation: https://github.com/ereyes01/kernel-mod-prez
Embedded Android system development workshop is focused on integrating new device with Android framework. Our hands-on approach makes Emertxe as the best institute to learn android system development training. This workshop deep dives into Android porting, Android Hardware Abstraction Layer (HAL), Android Services and Linux device driver ecosystem. This workshop based training program will enable you to efficiently integrate new hardware with Android HAL / Framework.
Linux has emerged as a number one choice for developing OS based Embedded Systems. Open Source development model, Customizability, Portability, Tool chain availability are some reasons for this success. This course gives a practical perspective of customizing, building and bringing up Linux Kernel on an ARM based target hardware. It combines various previous modules you have learned, by combing Linux administration, Hardware knowledge, Linux as OS, C/Computer programming areas. After bringing up Linux, you can port any of the existing applications into the target hardware.
Part 01 Linux Kernel Compilation (Ubuntu)Tushar B Kute
Presentation on "Linux Kernel Compilation" (Ubuntu based).
Presented at Army Institute of Technology, Pune for FDP on "Basics of Linux Kernel Programming". by Tushar B Kute (http://tusharkute.com).
Some basic knowledges required for beginners in writing linux kernel module - with a description of linux source tree, so that the idea of where and how develops. The working of insmod and rmmod commands are described also.
Android Things is the latest attempt from Google to connect the dots between the cloud and devices by introducing an OS that is exclusively built for IoT devices. Initially announced as project Brillo, Android Things helps developers to build devices faster and enable them integrate with cloud services. This presentation traces the architectural aspects of Android Things by connecting it back with Embedded Linux, Embedded Android and Brillo.
Often called as the Swiss Army Knife of Embedded Linux, BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. It is written with size-optimization
and limited resources in mind. Here is a presentation that details about BusyBox.
U-Boot, a boot loader for Embedded boards based on PowerPC, ARM, MIPS and several other processors, which can be installed in a boot ROM and used to initialize and test the hardware or to download and run application
code.
C has been the most commonly used language. This slideshare is all about the introduction to Advanced C. You will learn the fundamentals and the problem solving skills. You will also get an idea on building algorithms and the conditions regarding it. There are also slides which will give knowledge about operators and their types. As a whole you will gain knowledge on three important fundamentals of C.
There is a surge in number of sensors / devices that are getting connected under the umbrella of Internet-Of-Things (IoT). These devices need to be integrated into the Android system and accessed via applications, which is covered in the course. Our Android system development course curriculum over weekends with practicals ensures you learn all critical components to get started.
Getting started with setting up embedded platform requires audience to understand some of the key aspects of Linux. Starting with basics of Linux this presentation talks about basic commands, vi editor, shell scripting and advanced commands
Embedded Android System Development - Part II talks about Hardware Abstraction Layer (HAL). HAL is an interfacing layer through which Android service can place a request to device. Uses functions provided by Linux system to service the request from android framework. A C/C++ layer with purely vendor specific implementation. Packaged into modules (.so) file & loaded by Android system at appropriate time
This is the presentation I gave on Linux kernel modules at the Linux Meetup in Austin, TX, on 2/5/2015.
http://www.meetup.com/linux-85/events/185946802/
Code referred to in the presentation: https://github.com/ereyes01/kernel-mod-prez
Embedded Android system development workshop is focused on integrating new device with Android framework. Our hands-on approach makes Emertxe as the best institute to learn android system development training. This workshop deep dives into Android porting, Android Hardware Abstraction Layer (HAL), Android Services and Linux device driver ecosystem. This workshop based training program will enable you to efficiently integrate new hardware with Android HAL / Framework.
Linux has emerged as a number one choice for developing OS based Embedded Systems. Open Source development model, Customizability, Portability, Tool chain availability are some reasons for this success. This course gives a practical perspective of customizing, building and bringing up Linux Kernel on an ARM based target hardware. It combines various previous modules you have learned, by combing Linux administration, Hardware knowledge, Linux as OS, C/Computer programming areas. After bringing up Linux, you can port any of the existing applications into the target hardware.
Part 01 Linux Kernel Compilation (Ubuntu)Tushar B Kute
Presentation on "Linux Kernel Compilation" (Ubuntu based).
Presented at Army Institute of Technology, Pune for FDP on "Basics of Linux Kernel Programming". by Tushar B Kute (http://tusharkute.com).
Some basic knowledges required for beginners in writing linux kernel module - with a description of linux source tree, so that the idea of where and how develops. The working of insmod and rmmod commands are described also.
Android Things is the latest attempt from Google to connect the dots between the cloud and devices by introducing an OS that is exclusively built for IoT devices. Initially announced as project Brillo, Android Things helps developers to build devices faster and enable them integrate with cloud services. This presentation traces the architectural aspects of Android Things by connecting it back with Embedded Linux, Embedded Android and Brillo.
Often called as the Swiss Army Knife of Embedded Linux, BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. It is written with size-optimization
and limited resources in mind. Here is a presentation that details about BusyBox.
U-Boot, a boot loader for Embedded boards based on PowerPC, ARM, MIPS and several other processors, which can be installed in a boot ROM and used to initialize and test the hardware or to download and run application
code.
C has been the most commonly used language. This slideshare is all about the introduction to Advanced C. You will learn the fundamentals and the problem solving skills. You will also get an idea on building algorithms and the conditions regarding it. There are also slides which will give knowledge about operators and their types. As a whole you will gain knowledge on three important fundamentals of C.
There is a surge in number of sensors / devices that are getting connected under the umbrella of Internet-Of-Things (IoT). These devices need to be integrated into the Android system and accessed via applications, which is covered in the course. Our Android system development course curriculum over weekends with practicals ensures you learn all critical components to get started.
Getting started with setting up embedded platform requires audience to understand some of the key aspects of Linux. Starting with basics of Linux this presentation talks about basic commands, vi editor, shell scripting and advanced commands
Communication protocols (like UART, SPI, I2C) play an very important role in Micro-controlled based embedded systems development. These protocols helps the main board to communicate with different peripherals by interfacing mechanism. Here is a presentation that talks about how these protocols actually work.
Lot of book tells about what is programming. Many also tell how to write a program, but very few cover the critical aspect of translating logic into a program. Specifically, in this fast paced industry, when you don't have time to think to program, this course comes really handy. It builds on the basics of programming, smooth sailing through the advanced nitty-gritty’s of the Advanced C language by translating logic to code
Data Structures, which is also called as Abstract Data Types (ADT) provide powerful options for programmer. Here is a tutorial which talks about various ADTs - Linked Lists, Stacks, Queues and Sorting Algorithms
Embedded systems domain offers great career opportunity for fresh engineers. Team Emertxe had a seminar session at MVJ college of engineering, Bangalore by sharing details about the same topic.
Emertxe Information Technologies (http://www.emertxe.com) is a pioneer IT finishing school based out of Bangalore India. We offer best-in-class trainings (instructor lead, workshops, online) for making individuals business ready. Our portfolio consist of Embedded systems, Cloud computing, Mobile Application, Software Engineering.
In the Embedded side, Linux is been our center of everything we do. Our Linux portfolio consist of four major areas: Linux Systems, Embedded Linux, Linux Internals & Networking, Device drivers. Each area has multiple topics that can be targeted for students, corporate and universities. For any queries please feel free to write to us at training@emertxe.com
Coming up with optimized C program for Embedded Systems consist of multiple challenges. This presentation talks about various methods about optimizing C programs in Embedded environment. It also has some interesting tips, Do's and Dont's that will offer practical help for an Embedded programmer.
here you will get basic idea about TERMINAL. you learn some basic commands. with the help of that commands you can make new folder(directory), new file with .txt or any other extension.you will learn HOW to make multiple folder in just one second. you will find Important information about the Linux terminal.
Emertxe Certified Embedded Professional (ECEP) is a flagship job-oriented training program offered by Emertxe. This slide deck has induction detail about course structure and delivery.
In 5-2020, I and Minh have a sharing session about Sync, Async, and Multi-threading in C#.
We believe this is one of the most important things when working with .Net technology.
This sharing is aiming to Junior Dev, or even Sr Dev or anyone interested in Sync, Async, and Multi-threading.
I hope it will bring you some values.
Multithreaded fundamentals
The thread class and runnable interface
Creating a thread
Creating multiple threads
Determining when a thread ends
Thread priorities
Synchronization
Using synchronized methods
The synchronized statement
Thread communication using notify(), wait() and notifyall()
Suspending , resuming and stopping threads
This ppt gives a general idea about the multithreading concepts in the java programming language. hope you find it useful
P.S :
sorry there is a correction in one of the slides
where i have entered implements thread
it is wrong it is actually implements Runnable
thank you!
The objectives of Multithreaded Programming in Operating Systems are:
- To introduce the notion of a thread—a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems.
- To discuss the APIs for the Pthreads, Windows, and Java thread libraries
- To explore several strategies that provide implicit threading.
- To examine issues related to multithreaded programming.
- To cover operating system support for threads in Windows and Linux.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
The field of Information retrieval (IR) is currently undergoing a transformative shift, at least partly due to the emerging applications of generative AI to information access. In this talk, we will deliberate on the sociotechnical implications of generative AI for information access. We will argue that there is both a critical necessity and an exciting opportunity for the IR community to re-center our research agendas on societal needs while dismantling the artificial separation between the work on fairness, accountability, transparency, and ethics in IR and the rest of IR research. Instead of adopting a reactionary strategy of trying to mitigate potential social harms from emerging technologies, the community should aim to proactively set the research agenda for the kinds of systems we should build inspired by diverse explicitly stated sociotechnical imaginaries. The sociotechnical imaginaries that underpin the design and development of information access technologies needs to be explicitly articulated, and we need to develop theories of change in context of these diverse perspectives. Our guiding future imaginaries must be informed by other academic fields, such as democratic theory and critical theory, and should be co-developed with social science scholars, legal scholars, civil rights and social justice activists, and artists, among others.
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
3. Threads
● Threads, like processes, are a mechanism to allow a program
to do more than one thing at a time
● As with processes, threads appear to run concurrently
● The Linux kernel schedules them asynchronously, interrupting
each thread from time to time to give others a chance to
execute
● Threads are a finer-grained unit of execution than processes
● That thread can create additional threads; all these threads
run the same program in the same process
● But each thread may be executing a different part of the
program at any given time
4. Threads
Single and Multi threaded Process
Threads are similar to handling multiple functions in parallel. Since they share
same code & data segments, care to be taken by programmer to avoid issues.
Single Threaded Process
code data files
registers
stack
thread
Multi Threaded Process
code data files
registers
stack
thread
registers
stack
thread
registers
stack
thread
5. Threads
Advantages
● Takes less time to create a new thread in an existing
process than to create a brand new process
● Switching between threads is faster than a normal
context switch
● Threads enhance efficiency in communication between
different executing programs
● No kernel involved
6. Threads
pthread API's
● GNU/Linux implements the POSIX standard thread API
(known as pthreads)
● All thread functions and data types are declared in the
header file <pthread.h>
● The pthread functions are not included in the standard C
library
● Instead, they are in libpthread, so you should add
-lpthread to the command line when you link your
program
Using libpthread is a very good example to understand differences between
functions, library functions and system calls
7. Threads
Creation
● The pthread_create function creates a new thread
Function Meaning
int pthread_create(
pthread_t *thread,
const pthread_attr_t *attr,
void *(*start_routine) (void *),
void *arg)
A pointer to a pthread_t variable, in which the
thread ID of the new thread is stored
A pointer to a thread attribute object. If you
pass NULL as the thread attribute, a thread will
be created with the default thread attributes
A pointer to the thread function. This is an
ordinary function pointer, of this type: void* (*)
(void*)
A thread argument value of type void *.
Whatever you pass is simply passed as the
argument to the thread function when thread
begins executing
8. Threads
Creation
● A call to pthread_create returns immediately, and the
original thread continues executing the instructions
following the call
● Meanwhile, the new thread begins executing the thread
function
● Linux schedules both threads asynchronously
● Programs must not rely on the relative order in which
instructions are executed in the two threads
9. Threads
Compilation
● Use the following command to compile the programs
using thread libraries
$ gcc -o <output_file> <input_file.c> -lpthread
10. Threads
Joining
● It is quite possible that output created by a thread needs to be
integrated for creating final result
● So the main program may need to wait for threads to
complete actions
● The pthread_join() function helps to achieve this purpose
Function Meaning
int pthread_join(
pthread_t thread,
void **value_ptr)
Thread ID of the thread to wait
Pointer to a void* variable that will receive
thread finished value
If you don’t care about the thread return
value, pass NULL as the second argument.
11. Threads
Passing Data
● The thread argument provides a convenient method of
passing data to threads
● Because the type of the argument is void*, though, you
can’t pass a lot of data directly via the argument
● Instead, use the thread argument to pass a pointer to
some structure or array of data
● Define a structure for each thread function, which
contains the “parameters” that the thread function
expects
● Using the thread argument, it’s easy to reuse the same
thread function for many threads. All these threads
execute the same code, but on different data
12. Threads
Return Values
● If the second argument you pass to pthread_join is non-
null, the thread’s return value will be placed in the
location pointed to by that argument
● The thread return value, like the thread argument, is of
type void*
● If you want to pass back a single int or other small
number, you can do this easily by casting the value to
void* and then casting back to the appropriate type after
calling pthread_join
13. Threads
Attributes
● Thread attributes provide a mechanism for fine-tuning
the behaviour of individual threads
● Recall that pthread_create accepts an argument that is a
pointer to a thread attribute object
● If you pass a null pointer, the default thread attributes
are used to configure the new thread
● However, you may create and customize a thread
attribute object to specify other values for the attributes
14. Threads
Joinable and Detached
● A thread may be created as a joinable thread (the default)
or as a detached thread
● A joinable thread, like a process, is not automatically cleaned
up by GNU/Linux when it terminates
● Thread’s exit state hangs around in the system (kind of like a
zombie process) until another thread calls pthread_join to
obtain its return value. Only then are its resources released
● A detached thread, in contrast, is cleaned up automatically
when it terminates
●
Because a detached thread is immediately cleaned up,
another thread may not synchronize on its completion by
using pthread_join or obtain its return value
16. Synchronization
why?
● Programming with threads is very tricky because most
threaded programs are concurrent programs
● In particular, there’s no way to know when the system will
schedule one thread to run and when it will run another
● One thread might run for a very long time, or the system
might switch among threads very quickly
● Debugging a threaded program is difficult because you cannot
always easily reproduce the behavior that caused the problem.
● You might run the program once and have everything work
fine; the next time you run it, it might crash.
● There’s no way to make the system schedule the threads
exactly the same way it did before.
17. Synchronization
Race Condition
● The ultimate cause of most bugs involving threads is that the
threads are accessing the same data.
● So the powerful aspects of threads can become a danger.
● If one thread is only partway through updating a data
structure when another thread accesses the same data
structure, it’s a problem.
● These bugs are called race conditions; the threads are racing
one another to change the same data structure.
18. Synchronization
Race Condition – The Problem
● Now suppose that two threads happen to finish a job at about
the same time, but only one job remains in the queue.
● The first thread checks whether job_queue is null; finding
that it isn’t, the thread enters the loop and stores the pointer
to the job object in next_job.
● At this point, Linux happens to interrupt the first thread and
schedules the second.
● The second thread also checks job_queue and finding it non-
null, also assigns the same job pointer to next_job.
● By unfortunate coincidence, we now have two threads
executing the same job.
19. Synchronization
Race Condition – The Solution
● To eliminate race conditions, you need a way to make
operations atomic.
● An atomic operation is indivisible and uninterruptible; once
the operation starts, it will not be paused or interrupted until
it completes, and no other operation will take place mean
while.
● In this particular example, you want to check job_queue; if
it’s not empty, remove the first job, all as a single atomic
operation.
20. Synchronization
Mutexes
● The solution to the job queue race condition problem is to let
only one thread access the queue of jobs at a time.
● GNU/Linux provides mutexes, short for MUTual EXclusion
locks.
● A mutex is a special lock that only one thread may lock at a
time.
● If a thread locks a mutex and then a second thread also tries
to lock the same mutex, the second thread is blocked, or put
on hold.
● Only when the first thread unlocks the mutex is the second
thread unblocked—allowed to resume execution.
21. Synchronization
Mutex - Creation
● To create a mutex, create a variable of type
pthread_mutex_t and pass a pointer to it to
pthread_mutex_init.
● The second argument to pthread_mutex_init is a
pointer to a mutex attribute object, which specifies
attributes of the mutex.
22. Synchronization
Mutex – Locking & Blocking
● A thread may attempt to lock a mutex by calling
pthread_mutex_lock on it.
● If the mutex was unlocked, it becomes locked and the
function returns immediately.
● If the mutex was locked by another thread,
pthread_mutex_lock blocks execution and returns only
eventually when the mutex is unlocked by the other thread.
● More than one thread may be blocked on a locked mutex at
one time.
● When the mutex is unlocked, only one of the blocked threads
is unblocked and allowed to lock the mutex; the other threads
stay blocked.
23. Synchronization
Mutex – Unlocking
● A call to pthread_mutex_unlock unlocks a mutex.
● This function should always be called from the same
thread that locked the mutex.
24. Synchronization
Semaphores
● A semaphore is a counter that can be used to synchronize
multiple threads.
● As with a mutex, GNU/Linux guarantees that checking or
modifying the value of a semaphore can be done safely,
without creating a race condition.
● Each semaphore has a counter value, which is a non-negative
integer.
25. Synchronization
Semaphores - Operations
● A wait operation decrements the value of the
semaphore by 1. If the value is already zero, the
operation blocks until the value of the semaphore
becomes positive (due to the action of some other
thread). When the semaphore’s value becomes
positive, it is decremented by 1 and the wait
operation returns.
● A post operation increments the value of the
semaphore by 1. If the semaphore was previously
zero and other threads are blocked in a wait
operation on that semaphore, one of those threads is
unblocked and its wait operation completes (which
brings the semaphore’s value back to zero).
26. Synchronization
Semaphores - Variable
● A semaphore is represented by a sem_t variable.
● Before using it, you must initialize it using the
sem_init function, passing a pointer to the sem_t
variable.
● The second parameter should be zero, and the third
parameter is the semaphore’s initial value.
● If you no longer need a semaphore, it’s good to de-
allocate it with sem_destroy.
29. Signals
● Signals are used to notify a process of a particular event
● Signals make the process aware that something has
happened in the system
● Target process should perform some pre-defined actions
to handle signals
● This is called ‘signal handling’
● Actions may range from 'self termination' to 'clean-up'
31. Signals
Identification
Each signal in Linux has got a name starting with 'SIG' and
a number associated with it.
For example Signal 'SIGSEGV' has got a number 11.
This is defined in /usr/include/bits/signum.h *
* The path might vary on different distributions
32. Signals
Origins
● The kernel sends signals to processes in response to
specific conditions. For instance, any of these Signals
may be sent to a process that attempts to perform an
illegal operation :
– SIGBUS (bus error),
– SIGSEGV (segmentation violation),
● A Process may also send a Signal to another Process.
● A Process may also send a Signal to itself
33. Signals
Handling
● When a process receives a signal, it processes
● Immediate handling
● For all possible signals, the system defines a default
disposition or action to take when a signal occurs
● There are four possible default dispositions:
– Exit: Forces process to exit
– Core: Forces process to exit and create a core file
– Stop: Stops the process
– Ignore: Ignores the signal
● Handling can be done, called ‘signal handling’
34. Signals
Set Behaviour
● The sigaction function can be used to set a signal disposition
whose prototype is:
int sigaction(int signum, const struct sigaction *act, struct
sigaction *oldact);
● The first parameter is the signal number.
● The next two parameters are pointers to sigaction structures
● The first of these contains the desired disposition for that
signal number, while the second receives the previous
disposition
35. Signals
Note
● A signal handler should perform the minimum work necessary
to respond to the signal, and then return control to the main
program (or terminate the program).
● In most cases, this consists simply of recording the fact that a
signal occurred.
● The main program then checks periodically whether a signal
has occurred and reacts accordingly.
36. Signals
vs Interrupt
● Signals can be described as soft-interrupts
● The concept of 'signals' and 'signals handling' is
analogous to that of the 'interrupt' handling done by a
microprocessor
● When a signal is sent to a process or thread, a signal
handler may be entered (depending on the current
disposition of the signal), which is similar to the
system entering an interrupt handler as the result of
receiving an interrupt.
37. Signals
Process Termination
● Normally, a process terminates in one of two ways. Either the
executing program calls the exit function, or the program’s
main function returns.
● Each process has an exit code: a number that the process
returns to its parent. The exit code is the argument passed to
the exit function, or the value returned from main.
● A process may also terminate abnormally, in response to a
signal. For instance, the SIGBUS, SIGSEGV, and SIGFPE signals
mentioned previously cause the process to terminate.
38. Stay connected
About us: Emertxe is India’s one of the top IT finishing schools & self learning kits
provider. Our primary focus is on Embedded with diversification focus on Java,
Oracle and Android areas
Branch Office: Corporate Headquarters:
Emertxe Information Technologies, Emertxe Information Technologies,
No-1, 9th Cross, 5th Main, 83, Farah Towers, 1st
Floor,
Jayamahal Extension, MG Road,
Bangalore, Karnataka 560046 Bangalore, Karnataka - 560001
T: +91 809 555 7333 (M), +91 80 41289576 (L)
E: training@emertxe.com
https://www.facebook.com/Emertxe https://twitter.com/EmertxeTweet https://www.slideshare.net/EmertxeSlides