SlideShare a Scribd company logo
1 of 38
Hilos
Capítulo 5
Silberschatz Galvin
Hilos2
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos
Concepto
Beneficios
Hilos a nivel kérnel y a nivel usuario
Modelos multihilos
Hilos de Solaris 2
Hilos de Java
Hilos3
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos
Un hilo (o proceso ligero) es una unidad básica de utilización
del CPU; consiste de:
• Contador de programa
• Conjunto de registros
• Espacio de stack
Hilos4
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos
Un hilo comparte con sus hilos pares:
• Sección de código
• Sección de datos
• Recursos del sistema operativo
• En conjunto se les conoce como tarea
Un proceso tradicional o pesado, es igual a una tarea con un
hilo.
Hilos5
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
un proceso
un hilo
varios procesos
un hilo por proceso
varios procesos
varios hilos por proceso
un proceso
varios hilos
Hilos y procesos
Hilos6
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Código Datos Archivos Código Datos Archivos
Hilo Hilos
Mono-hilo Multi-hilo
Procesos con un solo hilo y con múltiples
hilos
Hilos7
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Bloque de
control
del hilo
Stack
del
usuario
Stack
del
usuario
Stack
del
kernel
Stack
del
Kernel
Espacio de
direcciones
del usuario
Espacio de
direcciones
del usuario
Bloque de
control del
proceso
Bloque
de control
del proceso
Hilo
Modelo de proceso
de un solo hilo
Modelo de proceso
multihilos
Bloque de
control
del hilo
Stack
del
usuario
Stack
del
kernel
Hilo
Bloque de
control
del hilo
Stack
del
usuario
Stack
del
kernel
Hilo
Modelos de procesos de un solo hilo y de
muchos hilos
Hilos8
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Multihilo
Sistema operativo que mantiene varios hilos de ejecución
dentro de un mismo proceso.
MS-DOS soporta un solo hilo.
UNIX soporta múltiples procesos de usuarios, pero sólo un hilo
por proceso.
Windows 2000, Solaris, Linux, Mac OS, OS/2 soportan múltiples
hilos.
Hilos9
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos
En una tarea donde hay múltiples hilos, mientras un hilo
servidor está bloqueado y esperando, otro hilo en la misma
tarea puede ejecutarse.
• Cooperación de múltiples hilos en la misma tarea aumenta la
tasa de trabajos por unidad tiempo y mejora el rendimiento.
• Aplicaciones que requieren compartir un buffer común
(productor-consumidor) sacan provecho de la utilización de
hilos.
Hilos10
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos
Los hilos proveen un mecanismo que permiten a procesos
secuenciales hacer llamadas bloqueantes mientras otros en
paralelo ejecutan otras operaciones.
Hilos11
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Beneficios
Compartición de recursos
Economía
Utilización de arquitecturas de múltiples procesadores
Hilos12
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos a nivel usuario
El manejo de los hilos lo hace una librería de hilos a nivel
usuario
Ejemplos
- Hilos POSIX
- Mach C-threads
- Hilos de Solaris
Hilos13
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos a nivel usuario (un CPU con dos
núcleos)
Nivel kérnel
(sistema
operativo)
Nivel usuario
Proceso de usuario gestiona y
planifica los múltiples hilos
Core CoreCPU
Hardware
Planificador del SO
Hilos14
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Ventajas de los hilos a nivel usuario
Los hilos podían implementarse en las aplicaciones que se
ejecutaban en sistemas operativos que no son capaces de
planificar hilos
• Ejemplo: Primeras implementaciones de UNIX
Hilos15
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Desventajas de los hilos a nivel usuario
El planificador del sistema operativo solo ve un hilo por proceso
 No ve los hilos a nivel usuario
 Usa un solo núcleo del procesador en un procesador que tiene
más de un núcleo
 No puede distribuir los hilos a nivel el usuario en los dos
núcleos
Hilos16
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos a nivel kérnel
Soportados por el kérnel
Ejemplos
• Windows 95/98/NT
• Solaris
• Linux
• Mac OS
Hilos17
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos a nivel kernel (con un CPU con un solo
núcleo)
Nivel kérnel
(sistema
operativo)
Nivel usuario
CoreCPU
Hardware
Planificador del SO
Hilos18
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos a nivel kernel (con un CPU con doble
núcleo)
Nivel kérnel
(sistema
operativo)
Nivel usuario
Core CoreCPU
Hardware
Planificador del SO
Hilos19
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Ventajas de los hilos a nivel kérnel
El proceso de usuario no se tiene que encargar de la
planificación de los hilos
Si tenemos un procesador con más de un núcelo, el Sistema
operativo puede planificar los hilos en diferentes núcleos
Hilos20
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Modelos multihilos
Muchos a uno
Uno a uno
Muchos a muchos
Hilos21
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Muchos a uno
Muchos hilos a nivel usuario mapeados a un hilo a nivel kérnel.
Usado en sistemas que no soportan hilos a nivel kérnel.
Hilos22
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Modelo muchos a uno
kk
Hilos23
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
EjecuciónListo
Listo
Relaciones entre estados de ULTs y estados
de procesos
Ejecución
Bloqueado
Bloqueado
Listo Ejecución
Bloqueado
Hilo 1
Hilo 2
Proceso B
Kernel
Usuario
Hilos24
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Uno a uno
Cada hilo a nivel usuario corresponde a un hilo del kérnel.
Ejemplos:
- Windows 95/98/NT
- OS/2
Hilos25
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Modelo uno a uno
kk kk kk kk
Hilo a nivel usuario
Hilo a nivel kérnel
Hilos26
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Modelo muchos a muchos
kk kkkk
Hilo a nivel usuario
Hilo a nivel kérnel
Hilos27
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Soporte de hilos en Solaris 2
Solaris 2 es una versión de UNIX con soporte para hilos a nivel
kernel y a nivel usuario, procesamiento simétrico y planificación
en tiempo real.
Hilos28
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Soporte de hilos en Solaris 2
LWP – Nivel intermedio entre los hilos a nivel kernel y los hilos
a nivel usuario.
Hilos29
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos en Solaris 2. Recursos necesarios para
los tipos de hilos
Hilos del kernel
• Estructura de datos pequeña y un stack
• El intercambio de hilos no requiere cambiar la información del
acceso a memoria
• Cambios de hilos relativamente rápidos
Hilos30
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos en Solaris 2. Recursos necesarios para
los tipos de hilos
LWP
• PCB con datos de los registros
• Información sobre la memoria
• El intercambio entre LWP es relativamente lento
Hilos31
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos en Solaris 2. Recursos necesarios para
los tipos de hilos
Hilos a nivel usuario
• Solo requiere un stack y un contador de programa
• No involucrar al kernel significa un intercambio rápido
• El kernel solo ve los LWP que soporta los hilos a nivel usuario
Hilos32
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Usuario
Núcleo
Hardware
Biblioteca
de hilos
Hilo a nivel de
usuario
Hilo del núcleo Proceso ligero Procesador
LL L LL L L L L
L P
P P P P P
Proceso 1 Proceso 2 Proceso 3 Proceso 4 Proceso 5
Ejemplo de la arquitectura multihilo de
Solaris
Hilos33
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Gestión de hilos básica
Un hilo tiene :
• Un identificador (ID)
• Una pila
• Una prioridad de ejecución
• Una dirección de inicio de ejecución.
Hilos34
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Gestión de hilos básica
(POSIX)
Se dice que un hilo es dinámico si se puede crear en cualquier
instante durante la ejecución.
En POSIX :
• los hilos se crean dinámicamente con la función
pthread_create.
• pthread_exit termina el hilo que la invoca.
Hilos35
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Gestión de hilos básica (POSIX), ejemplo:
Programa que crea un hilo donde muestra el mensaje “Hola
Mundo”
Para compilar el programa :
• $ cc -D_REENTRANT thread2.c -o thread2 -lpthread
Hilos36
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
int main()
{
pthread_create(a_thread,funcion_hilo);
pthread_join(a_thread);
}
funcion_hilo()
{
…
}
Crea un hilo
nuevo
Espera a que
termine el hilo
creado
Hilo principal
Hilo creado con la llamada
pthread_create
Hilos37
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Gestión de hilos básica
(POSIX)
Pthread_join()
• Hilo que ejecuta pthread_join, espera a que termine otro hilo
El hilo principal debe esperar a que terminen todos los hilos
creados
• Si el hilo principal no espera a que terminen los hilos creados,
al terminar termina el proceso con todos los hilos.
Hilos38
Copyright © 2006, Intel Corporation. All rights reserved.
Sistemas Operativos
Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners.
Hilos en memoria
Código
(compartido)
Datos
(compartidos)
Int cont=0 (var. Global)
Stack (de cada hilo)
Int i
(var local)
Stack (de cada hilo)
Int i
(var local)

More Related Content

Similar to Understanding Threads in Operating Systems

Features of modern intel microprocessors
Features of modern intel microprocessorsFeatures of modern intel microprocessors
Features of modern intel microprocessorsKrunal Siddhapathak
 
17294_HiperSockets.pdf
17294_HiperSockets.pdf17294_HiperSockets.pdf
17294_HiperSockets.pdfEeszt
 
Introduction ciot workshop premeetup
Introduction ciot workshop premeetupIntroduction ciot workshop premeetup
Introduction ciot workshop premeetupBeMyApp
 
Intel® MPI Library e OpenMP* - Intel Software Conference 2013
Intel® MPI Library e OpenMP* - Intel Software Conference 2013Intel® MPI Library e OpenMP* - Intel Software Conference 2013
Intel® MPI Library e OpenMP* - Intel Software Conference 2013Intel Software Brasil
 
Linux on Z13 and Simulatenus Multithreading - Sebastien Llaurency
Linux on Z13 and Simulatenus Multithreading - Sebastien LlaurencyLinux on Z13 and Simulatenus Multithreading - Sebastien Llaurency
Linux on Z13 and Simulatenus Multithreading - Sebastien LlaurencyNRB
 
Intel Technologies for High Performance Computing
Intel Technologies for High Performance ComputingIntel Technologies for High Performance Computing
Intel Technologies for High Performance ComputingIntel Software Brasil
 
Intel® VTune™ Amplifier - Intel Software Conference 2013
Intel® VTune™ Amplifier - Intel Software Conference 2013Intel® VTune™ Amplifier - Intel Software Conference 2013
Intel® VTune™ Amplifier - Intel Software Conference 2013Intel Software Brasil
 
Apache HDFS Extended Attributes and Transparent Encryption
Apache HDFS Extended Attributes and Transparent EncryptionApache HDFS Extended Attributes and Transparent Encryption
Apache HDFS Extended Attributes and Transparent EncryptionUma Maheswara Rao Gangumalla
 
NFF-GO (YANFF) - Yet Another Network Function Framework
NFF-GO (YANFF) - Yet Another Network Function FrameworkNFF-GO (YANFF) - Yet Another Network Function Framework
NFF-GO (YANFF) - Yet Another Network Function FrameworkMichelle Holley
 
Using JavaScript to Build HTML5 Tools (Ian Maffett)
Using JavaScript to Build HTML5 Tools (Ian Maffett)Using JavaScript to Build HTML5 Tools (Ian Maffett)
Using JavaScript to Build HTML5 Tools (Ian Maffett)Future Insights
 
What are latest new features that DPDK brings into 2018?
What are latest new features that DPDK brings into 2018?What are latest new features that DPDK brings into 2018?
What are latest new features that DPDK brings into 2018?Michelle Holley
 
Intel XDK - Philly JS
Intel XDK - Philly JSIntel XDK - Philly JS
Intel XDK - Philly JSIan Maffett
 
Intel NFVi Enabling Kit Demo/Lab
Intel NFVi Enabling Kit Demo/LabIntel NFVi Enabling Kit Demo/Lab
Intel NFVi Enabling Kit Demo/LabMichelle Holley
 
OpenStack and z/VM – What is it and how do I get it?
OpenStack and z/VM – What is it and how do I get it?OpenStack and z/VM – What is it and how do I get it?
OpenStack and z/VM – What is it and how do I get it?Anderson Bassani
 
Methods and practices to analyze the performance of your application with Int...
Methods and practices to analyze the performance of your application with Int...Methods and practices to analyze the performance of your application with Int...
Methods and practices to analyze the performance of your application with Int...Intel Software Brasil
 
Cots moves to multicore: Wind River
Cots moves to multicore: Wind RiverCots moves to multicore: Wind River
Cots moves to multicore: Wind RiverKonrad Witte
 
Embree Ray Tracing Kernels
Embree Ray Tracing KernelsEmbree Ray Tracing Kernels
Embree Ray Tracing KernelsIntel® Software
 
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...Intel® Software
 
In The Trenches Optimizing UE4 for Intel
In The Trenches Optimizing UE4 for IntelIn The Trenches Optimizing UE4 for Intel
In The Trenches Optimizing UE4 for IntelIntel® Software
 

Similar to Understanding Threads in Operating Systems (20)

Features of modern intel microprocessors
Features of modern intel microprocessorsFeatures of modern intel microprocessors
Features of modern intel microprocessors
 
17294_HiperSockets.pdf
17294_HiperSockets.pdf17294_HiperSockets.pdf
17294_HiperSockets.pdf
 
Introduction ciot workshop premeetup
Introduction ciot workshop premeetupIntroduction ciot workshop premeetup
Introduction ciot workshop premeetup
 
Intel® MPI Library e OpenMP* - Intel Software Conference 2013
Intel® MPI Library e OpenMP* - Intel Software Conference 2013Intel® MPI Library e OpenMP* - Intel Software Conference 2013
Intel® MPI Library e OpenMP* - Intel Software Conference 2013
 
Linux on Z13 and Simulatenus Multithreading - Sebastien Llaurency
Linux on Z13 and Simulatenus Multithreading - Sebastien LlaurencyLinux on Z13 and Simulatenus Multithreading - Sebastien Llaurency
Linux on Z13 and Simulatenus Multithreading - Sebastien Llaurency
 
Intel Technologies for High Performance Computing
Intel Technologies for High Performance ComputingIntel Technologies for High Performance Computing
Intel Technologies for High Performance Computing
 
Intel® VTune™ Amplifier - Intel Software Conference 2013
Intel® VTune™ Amplifier - Intel Software Conference 2013Intel® VTune™ Amplifier - Intel Software Conference 2013
Intel® VTune™ Amplifier - Intel Software Conference 2013
 
Apache HDFS Extended Attributes and Transparent Encryption
Apache HDFS Extended Attributes and Transparent EncryptionApache HDFS Extended Attributes and Transparent Encryption
Apache HDFS Extended Attributes and Transparent Encryption
 
NFF-GO (YANFF) - Yet Another Network Function Framework
NFF-GO (YANFF) - Yet Another Network Function FrameworkNFF-GO (YANFF) - Yet Another Network Function Framework
NFF-GO (YANFF) - Yet Another Network Function Framework
 
Using JavaScript to Build HTML5 Tools (Ian Maffett)
Using JavaScript to Build HTML5 Tools (Ian Maffett)Using JavaScript to Build HTML5 Tools (Ian Maffett)
Using JavaScript to Build HTML5 Tools (Ian Maffett)
 
What are latest new features that DPDK brings into 2018?
What are latest new features that DPDK brings into 2018?What are latest new features that DPDK brings into 2018?
What are latest new features that DPDK brings into 2018?
 
Intel XDK - Philly JS
Intel XDK - Philly JSIntel XDK - Philly JS
Intel XDK - Philly JS
 
Intel NFVi Enabling Kit Demo/Lab
Intel NFVi Enabling Kit Demo/LabIntel NFVi Enabling Kit Demo/Lab
Intel NFVi Enabling Kit Demo/Lab
 
Intel tools to optimize HPC systems
Intel tools to optimize HPC systemsIntel tools to optimize HPC systems
Intel tools to optimize HPC systems
 
OpenStack and z/VM – What is it and how do I get it?
OpenStack and z/VM – What is it and how do I get it?OpenStack and z/VM – What is it and how do I get it?
OpenStack and z/VM – What is it and how do I get it?
 
Methods and practices to analyze the performance of your application with Int...
Methods and practices to analyze the performance of your application with Int...Methods and practices to analyze the performance of your application with Int...
Methods and practices to analyze the performance of your application with Int...
 
Cots moves to multicore: Wind River
Cots moves to multicore: Wind RiverCots moves to multicore: Wind River
Cots moves to multicore: Wind River
 
Embree Ray Tracing Kernels
Embree Ray Tracing KernelsEmbree Ray Tracing Kernels
Embree Ray Tracing Kernels
 
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...
 
In The Trenches Optimizing UE4 for Intel
In The Trenches Optimizing UE4 for IntelIn The Trenches Optimizing UE4 for Intel
In The Trenches Optimizing UE4 for Intel
 

More from Ichinose 11

Mapa mental gilberto ramos itdo acosta_erik solis
Mapa mental gilberto ramos itdo acosta_erik solisMapa mental gilberto ramos itdo acosta_erik solis
Mapa mental gilberto ramos itdo acosta_erik solisIchinose 11
 
Laboratorio n4 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n4 sistemas_operativos_gilberto_ramos_9-748-1883Laboratorio n4 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n4 sistemas_operativos_gilberto_ramos_9-748-1883Ichinose 11
 
Laboratorio n3 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n3 sistemas_operativos_gilberto_ramos_9-748-1883Laboratorio n3 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n3 sistemas_operativos_gilberto_ramos_9-748-1883Ichinose 11
 
Laboratorio#2 sistemas operativos gilberto ramos..
Laboratorio#2 sistemas operativos gilberto ramos..Laboratorio#2 sistemas operativos gilberto ramos..
Laboratorio#2 sistemas operativos gilberto ramos..Ichinose 11
 
Laboratorio n1 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n1 sistemas_operativos_gilberto_ramos_9-748-1883 Laboratorio n1 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n1 sistemas_operativos_gilberto_ramos_9-748-1883 Ichinose 11
 
Sistema compañeros
Sistema         compañerosSistema         compañeros
Sistema compañerosIchinose 11
 
Presentacion memoria
Presentacion memoriaPresentacion memoria
Presentacion memoriaIchinose 11
 
Sincronización entre procesos
Sincronización entre procesosSincronización entre procesos
Sincronización entre procesosIchinose 11
 

More from Ichinose 11 (12)

Mapa mental gilberto ramos itdo acosta_erik solis
Mapa mental gilberto ramos itdo acosta_erik solisMapa mental gilberto ramos itdo acosta_erik solis
Mapa mental gilberto ramos itdo acosta_erik solis
 
Laboratorio n4 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n4 sistemas_operativos_gilberto_ramos_9-748-1883Laboratorio n4 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n4 sistemas_operativos_gilberto_ramos_9-748-1883
 
Laboratorio n3 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n3 sistemas_operativos_gilberto_ramos_9-748-1883Laboratorio n3 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n3 sistemas_operativos_gilberto_ramos_9-748-1883
 
Laboratorio#2 sistemas operativos gilberto ramos..
Laboratorio#2 sistemas operativos gilberto ramos..Laboratorio#2 sistemas operativos gilberto ramos..
Laboratorio#2 sistemas operativos gilberto ramos..
 
Laboratorio n1 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n1 sistemas_operativos_gilberto_ramos_9-748-1883 Laboratorio n1 sistemas_operativos_gilberto_ramos_9-748-1883
Laboratorio n1 sistemas_operativos_gilberto_ramos_9-748-1883
 
Ubuntu touch
Ubuntu  touchUbuntu  touch
Ubuntu touch
 
Sistema compañeros
Sistema         compañerosSistema         compañeros
Sistema compañeros
 
Archivos 2016
Archivos 2016Archivos 2016
Archivos 2016
 
Bloqueos _
Bloqueos _Bloqueos _
Bloqueos _
 
Presentacion memoria
Presentacion memoriaPresentacion memoria
Presentacion memoria
 
Memoria 3
Memoria 3Memoria 3
Memoria 3
 
Sincronización entre procesos
Sincronización entre procesosSincronización entre procesos
Sincronización entre procesos
 

Recently uploaded

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Understanding Threads in Operating Systems

  • 2. Hilos2 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos Concepto Beneficios Hilos a nivel kérnel y a nivel usuario Modelos multihilos Hilos de Solaris 2 Hilos de Java
  • 3. Hilos3 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos Un hilo (o proceso ligero) es una unidad básica de utilización del CPU; consiste de: • Contador de programa • Conjunto de registros • Espacio de stack
  • 4. Hilos4 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos Un hilo comparte con sus hilos pares: • Sección de código • Sección de datos • Recursos del sistema operativo • En conjunto se les conoce como tarea Un proceso tradicional o pesado, es igual a una tarea con un hilo.
  • 5. Hilos5 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. un proceso un hilo varios procesos un hilo por proceso varios procesos varios hilos por proceso un proceso varios hilos Hilos y procesos
  • 6. Hilos6 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Código Datos Archivos Código Datos Archivos Hilo Hilos Mono-hilo Multi-hilo Procesos con un solo hilo y con múltiples hilos
  • 7. Hilos7 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Bloque de control del hilo Stack del usuario Stack del usuario Stack del kernel Stack del Kernel Espacio de direcciones del usuario Espacio de direcciones del usuario Bloque de control del proceso Bloque de control del proceso Hilo Modelo de proceso de un solo hilo Modelo de proceso multihilos Bloque de control del hilo Stack del usuario Stack del kernel Hilo Bloque de control del hilo Stack del usuario Stack del kernel Hilo Modelos de procesos de un solo hilo y de muchos hilos
  • 8. Hilos8 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Multihilo Sistema operativo que mantiene varios hilos de ejecución dentro de un mismo proceso. MS-DOS soporta un solo hilo. UNIX soporta múltiples procesos de usuarios, pero sólo un hilo por proceso. Windows 2000, Solaris, Linux, Mac OS, OS/2 soportan múltiples hilos.
  • 9. Hilos9 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos En una tarea donde hay múltiples hilos, mientras un hilo servidor está bloqueado y esperando, otro hilo en la misma tarea puede ejecutarse. • Cooperación de múltiples hilos en la misma tarea aumenta la tasa de trabajos por unidad tiempo y mejora el rendimiento. • Aplicaciones que requieren compartir un buffer común (productor-consumidor) sacan provecho de la utilización de hilos.
  • 10. Hilos10 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos Los hilos proveen un mecanismo que permiten a procesos secuenciales hacer llamadas bloqueantes mientras otros en paralelo ejecutan otras operaciones.
  • 11. Hilos11 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Beneficios Compartición de recursos Economía Utilización de arquitecturas de múltiples procesadores
  • 12. Hilos12 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos a nivel usuario El manejo de los hilos lo hace una librería de hilos a nivel usuario Ejemplos - Hilos POSIX - Mach C-threads - Hilos de Solaris
  • 13. Hilos13 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos a nivel usuario (un CPU con dos núcleos) Nivel kérnel (sistema operativo) Nivel usuario Proceso de usuario gestiona y planifica los múltiples hilos Core CoreCPU Hardware Planificador del SO
  • 14. Hilos14 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Ventajas de los hilos a nivel usuario Los hilos podían implementarse en las aplicaciones que se ejecutaban en sistemas operativos que no son capaces de planificar hilos • Ejemplo: Primeras implementaciones de UNIX
  • 15. Hilos15 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Desventajas de los hilos a nivel usuario El planificador del sistema operativo solo ve un hilo por proceso  No ve los hilos a nivel usuario  Usa un solo núcleo del procesador en un procesador que tiene más de un núcleo  No puede distribuir los hilos a nivel el usuario en los dos núcleos
  • 16. Hilos16 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos a nivel kérnel Soportados por el kérnel Ejemplos • Windows 95/98/NT • Solaris • Linux • Mac OS
  • 17. Hilos17 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos a nivel kernel (con un CPU con un solo núcleo) Nivel kérnel (sistema operativo) Nivel usuario CoreCPU Hardware Planificador del SO
  • 18. Hilos18 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos a nivel kernel (con un CPU con doble núcleo) Nivel kérnel (sistema operativo) Nivel usuario Core CoreCPU Hardware Planificador del SO
  • 19. Hilos19 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Ventajas de los hilos a nivel kérnel El proceso de usuario no se tiene que encargar de la planificación de los hilos Si tenemos un procesador con más de un núcelo, el Sistema operativo puede planificar los hilos en diferentes núcleos
  • 20. Hilos20 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Modelos multihilos Muchos a uno Uno a uno Muchos a muchos
  • 21. Hilos21 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Muchos a uno Muchos hilos a nivel usuario mapeados a un hilo a nivel kérnel. Usado en sistemas que no soportan hilos a nivel kérnel.
  • 22. Hilos22 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Modelo muchos a uno kk
  • 23. Hilos23 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. EjecuciónListo Listo Relaciones entre estados de ULTs y estados de procesos Ejecución Bloqueado Bloqueado Listo Ejecución Bloqueado Hilo 1 Hilo 2 Proceso B Kernel Usuario
  • 24. Hilos24 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Uno a uno Cada hilo a nivel usuario corresponde a un hilo del kérnel. Ejemplos: - Windows 95/98/NT - OS/2
  • 25. Hilos25 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Modelo uno a uno kk kk kk kk Hilo a nivel usuario Hilo a nivel kérnel
  • 26. Hilos26 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Modelo muchos a muchos kk kkkk Hilo a nivel usuario Hilo a nivel kérnel
  • 27. Hilos27 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Soporte de hilos en Solaris 2 Solaris 2 es una versión de UNIX con soporte para hilos a nivel kernel y a nivel usuario, procesamiento simétrico y planificación en tiempo real.
  • 28. Hilos28 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Soporte de hilos en Solaris 2 LWP – Nivel intermedio entre los hilos a nivel kernel y los hilos a nivel usuario.
  • 29. Hilos29 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos en Solaris 2. Recursos necesarios para los tipos de hilos Hilos del kernel • Estructura de datos pequeña y un stack • El intercambio de hilos no requiere cambiar la información del acceso a memoria • Cambios de hilos relativamente rápidos
  • 30. Hilos30 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos en Solaris 2. Recursos necesarios para los tipos de hilos LWP • PCB con datos de los registros • Información sobre la memoria • El intercambio entre LWP es relativamente lento
  • 31. Hilos31 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos en Solaris 2. Recursos necesarios para los tipos de hilos Hilos a nivel usuario • Solo requiere un stack y un contador de programa • No involucrar al kernel significa un intercambio rápido • El kernel solo ve los LWP que soporta los hilos a nivel usuario
  • 32. Hilos32 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Usuario Núcleo Hardware Biblioteca de hilos Hilo a nivel de usuario Hilo del núcleo Proceso ligero Procesador LL L LL L L L L L P P P P P P Proceso 1 Proceso 2 Proceso 3 Proceso 4 Proceso 5 Ejemplo de la arquitectura multihilo de Solaris
  • 33. Hilos33 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Gestión de hilos básica Un hilo tiene : • Un identificador (ID) • Una pila • Una prioridad de ejecución • Una dirección de inicio de ejecución.
  • 34. Hilos34 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Gestión de hilos básica (POSIX) Se dice que un hilo es dinámico si se puede crear en cualquier instante durante la ejecución. En POSIX : • los hilos se crean dinámicamente con la función pthread_create. • pthread_exit termina el hilo que la invoca.
  • 35. Hilos35 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Gestión de hilos básica (POSIX), ejemplo: Programa que crea un hilo donde muestra el mensaje “Hola Mundo” Para compilar el programa : • $ cc -D_REENTRANT thread2.c -o thread2 -lpthread
  • 36. Hilos36 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. int main() { pthread_create(a_thread,funcion_hilo); pthread_join(a_thread); } funcion_hilo() { … } Crea un hilo nuevo Espera a que termine el hilo creado Hilo principal Hilo creado con la llamada pthread_create
  • 37. Hilos37 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Gestión de hilos básica (POSIX) Pthread_join() • Hilo que ejecuta pthread_join, espera a que termine otro hilo El hilo principal debe esperar a que terminen todos los hilos creados • Si el hilo principal no espera a que terminen los hilos creados, al terminar termina el proceso con todos los hilos.
  • 38. Hilos38 Copyright © 2006, Intel Corporation. All rights reserved. Sistemas Operativos Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Hilos en memoria Código (compartido) Datos (compartidos) Int cont=0 (var. Global) Stack (de cada hilo) Int i (var local) Stack (de cada hilo) Int i (var local)

Editor's Notes

  1. #include <pthread.h> int pthread_create(pthread_t *tid, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); pthread_create crea un hilo y lo coloca en la cola de hilos. tid apunta al ID del hilo que se crea. Los atributos del hilo se encapsulan en el objeto atributo al que apunta attr si este es null, el nuevo hilo tendrá los atributos por omisión. start_routine, es el nombre de una rutina a la que el hilo invoca. El parámetro que se le especifica a start_routine es arg. #include <pthread.h> void pthread_exit(void *value_ptr); La función pthread_exit termina el hilo que la invoca. El valor del parámetro value_ptr queda disponible para pthread_join.
  2. #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h> void *thread_function(void *arg); char message[] = "Hola mundo"; int main() { int res; pthread_t a_thread; void *thread_result; /* Aquí se crea el hilo */ res = pthread_create(&a_thread, NULL, thread_function, (void *)message); if (res != 0) { perror("Thread creation failed"); exit(EXIT_FAILURE); } printf("Esperando que el hilo termine...\n"); res = pthread_join(a_thread, &thread_result); if (res != 0) { perror("La unión del hilo ha fallado"); exit(EXIT_FAILURE); } printf("Hilo unido, regresó %s\n", (char *)thread_result); printf("El mensaje es %s\n", message); exit(EXIT_SUCCESS); } void *thread_function(void *arg) { printf("la función del hilo está corriendo. El Argumento fué %s\n", (char *) arg); sleep(3); strcpy(message, "Adios!"); pthread_exit("Gracias por el tiempo del CPU"); }
  3. #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h> // Definen funciones para manejo de hilos void *thread_function(void *arg); // Función donde inicia el hilo int cont=0; // Es la misma para ambos hilos // Global está en el segmento de datos int main() { // Definición de variables int res; pthread_t a_thread; // Identificador del hilo void *thread_result; int i; // Es local, por lo tanto está en el segmento de stack de cada hilo /* Aquí se crea el hilo */ res = pthread_create(&a_thread, NULL, thread_function,NULL); if (res != 0) { perror("Thread creation failed"); exit(EXIT_FAILURE); } // Hilo principal for(i=1;i<=10;i++) { printf("%d\n",i); cont++; printf("Hilo principal dice cont=%d\n",cont); sleep(1); } printf("Esperando que el hilo termine...\n"); // Esperar a que termine el hilo cuyo identificador es a_thread res = pthread_join(a_thread, &thread_result); if (res != 0) { perror("La unión del hilo ha fallado"); exit(EXIT_FAILURE); } printf("Hilo unido, regresó %s\n", (char *)thread_result); exit(EXIT_SUCCESS); } // Función donde inicia la ejecución el hilo secundario void *thread_function(void *arg) { int i; // Es local, por lo tanto está en el segmento de stack de cada hilo for(i=10;i>0;i--) { printf("%d\n",i); printf("Hilo secundario dice cont=%d\n",cont); sleep(1); } pthread_exit("Gracias por el tiempo del CPU"); }