Beruflich Dokumente
Kultur Dokumente
Capítulo 5
Silberschatz Galvin
Hilos
Concepto
Beneficios
Hilos a nivel kérnel y a nivel usuario
Modelos multihilos
Hilos de Solaris 2
Hilos de Java
Sistemas Operativos
2 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
3 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
4 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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 y procesos
un proceso un proceso
un hilo varios hilos
Sistemas Operativos
5 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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.
Procesos con un solo hilo y con múltiples
hilos
Hilo Hilos
Mono-hilo Multi-hilo
Sistemas Operativos
6 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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 de procesos de un solo hilo y de
muchos hilos
Sistemas Operativos
7 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
8 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
9 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
10 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
11 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Ejemplos
- Hilos POSIX
- Mach C-threads
- Hilos de Solaris
Sistemas Operativos
12 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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)
Planificador del SO
Hardware
Sistemas Operativos
13 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
14 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
15 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Ejemplos
• Windows 95/98/NT
• Solaris
• Linux
• Mac OS
Sistemas Operativos
16 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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 usuario
Nivel kérnel
(sistema
operativo)
Planificador del SO
Hardware
CPU Core
Sistemas Operativos
17 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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 usuario
Nivel kérnel
(sistema
operativo)
Planificador del SO
Hardware
CPU Core Core
Sistemas Operativos
18 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
19 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
20 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
21 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
22 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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.
Relaciones entre estados de ULTs y estados
de procesos
Hilo 1
Hilo 2
Listo Ejecución
Listo Ejecución
Bloqueado
Bloqueado
Usuario
Kernel
Listo Ejecución
Bloqueado
23 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Ejemplos:
- Windows 95/98/NT
- OS/2
Sistemas Operativos
24 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
25 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
26 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
27 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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.
Sistemas Operativos
28 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
29 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
30 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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
Sistemas Operativos
31 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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.
Ejemplo de la arquitectura multihilo de
Solaris
Usuario Biblioteca
de hilos
L L L L L L L L L
Núcleo
Hardware P P P P P
Hilo a nivel de
usuario
Hilo del núcleo L Proceso ligero P Procesador
Sistemas Operativos
32 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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.
Sistemas Operativos
33 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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.
Sistemas Operativos
34 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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:
Sistemas Operativos
35 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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()
{
Espera a que
pthread_join(a_thread);
termine el hilo
creado
}
Hilo principal
funcion_hilo()
{
…
Hilo creado con la llamada
}
pthread_create
Sistemas Operativos
36 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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.
Sistemas Operativos
37 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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)
Sistemas Operativos
38 Hilos
Copyright © 2006, Intel Corporation. All rights reserved.
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.