Skip to content

Create threads that attempt to cross a bridge if it is empty based on direction. The output is in the console with pretty prints.

Notifications You must be signed in to change notification settings

ediloaz/Threads-sync-in-C

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Tarea 1: SincronizaciΓ³n de "threads"

Del curso Sistema Operativos Avanzados, de la MaestrΓ­a de Ciencias de la ComputaciΓ³n del TecnolΓ³gico de Costa Rica.

Equipo de trabajo:
  • Carvajal Barboza Nicole
  • GonzΓ‘lez Villanueva Ruben
  • LΓ³pez DΓ­az Edisson
  • Mena Kikut Otto
  • Soto Rojas Cristina

Uso del programa

CompilaciΓ³n

Se utiliza el compilador de GNU, el GCC, usando la siguiente lΓ­nea:

gcc main.c -o main -lpthread -lm -w

  • main.c: Nombre del archivo principal.
  • -o: Indica el nombre del archivo de salida.
  • main: Nombre del archivo de salida.
  • -lpthread: Indica que se usarΓ‘n pthreads.
  • -lm: Indica que se usarΓ‘ math.
  • -w: Indica que no imprima warnings.

EjecuciΓ³n

Se usa el archivo de salida resultante de la compilaciΓ³n "main". Para ejecutarlo es suficiente con la siguiente lΓ­nea: ./main

Sin embargo Γ©sto ejecutarΓ‘ el programa con variables estΓ‘ndares que hemos definido, para indicar cuΓ‘ntos carros vienen del Γ©ste y del oeste se usan los parΓ‘metros, con la siguiente lΓ­nea:

./main 4 5

Donde el primero, el 4, indica la cantidad de carros que quieren ingresar desde el este/derecha, y el segundo, el 5, la cantidad de carros que quieren ingresar desde el oeste/izquierda.

Opciones extras incluΓ­das

Se incluyeron dos parΓ‘metros extra que son opcionales para indicar el lambda que se usarΓ‘ para la funciΓ³n exponencial para cada direcciΓ³n, este/derecha y oeste/izquierda. Se hace uso de la siguiente manera:

./main 4 5 6 7

Donde el tercero, el 6, indica el lambda el este/derecha, y el cuarto, el 7, el lambda para el oeste/izquierda.

No funcional en el programa

Actualmente todo funciona en el programa y se programΓ³ tal como se solicitΓ³ en el enunciado.





Otros

Ejecuciones del programa

A continuaciΓ³n dos ejecuciones del programa, mostrando el comando de ejecuciΓ³n y las lΓ­neas impresas en consola del resultado.

Caso 1

EjecuciΓ³n: ./main 3 3 15 15

Resultado:

Parameters set at: East cars: 3, West cars: 3, East lambda: 15, West lambda: 15
Before Thread
===================Left Times ============== 
Time = 2.612782 
Time = 4.853285 
Time = 8.171958 
===================Right Times ============== 
Time = 17.620624 
Time = 35.221855 
Time = 62.820526 
===================Total Times and Direction ==============
Time = 2.612782 Direction = -1 
Time = 4.853285 Direction = -1 
Time = 8.171958 Direction = -1 
Time = 17.620624 Direction = 1 
Time = 35.221855 Direction = 1 
Time = 62.820526 Direction = 1 


 ** BEGIN PROCESS TO PASS THE BRIDGE ** 


-655395072 (Left  ⬅️) Arrived a new car! πŸš™πŸ’¨ 
-655395072 (Left  ⬅️) I'm the fist, I allow the Left  ⬅️ direction 🟒 🟒 
-655395072 (Left  ⬅️) I'll pass the bridge in a row, and now I'm the last 🟒 

-663787776 (Left  ⬅️) Arrived a new car! πŸš™πŸ’¨ 
-663787776 (Left  ⬅️) It's my same direction 🟒 
-663787776 (Left  ⬅️) I'll pass the bridge in a row, and now I'm the last 🟒 
-655395072 (Left  ⬅️) I passed the bridge 🟒 

-672180480 (Left  ⬅️) Arrived a new car! πŸš™πŸ’¨ 
-672180480 (Left  ⬅️) It's my same direction 🟒 
-672180480 (Left  ⬅️) I'll pass the bridge in a row, and now I'm the last 🟒 
-663787776 (Left  ⬅️) I passed the bridge 🟒 
-672180480 (Left  ⬅️) I passed the bridge 🟒 
-672180480 (Left  ⬅️) I was the last, the bridge is empty 🟑 


-680573184 (Right ➑️) Arrived a new car! πŸš™πŸ’¨ 
-680573184 (Right ➑️) I'm the fist, I allow the Right ➑️ direction 🟒 🟒 
-680573184 (Right ➑️) I'll pass the bridge in a row, and now I'm the last 🟒 
-680573184 (Right ➑️) I passed the bridge 🟒 
-680573184 (Right ➑️) I was the last, the bridge is empty 🟑 


-688965888 (Right ➑️) Arrived a new car! πŸš™πŸ’¨ 
-688965888 (Right ➑️) I'm the fist, I allow the Right ➑️ direction 🟒 🟒 
-688965888 (Right ➑️) I'll pass the bridge in a row, and now I'm the last 🟒 
-688965888 (Right ➑️) I passed the bridge 🟒 
-688965888 (Right ➑️) I was the last, the bridge is empty 🟑 


-697358592 (Right ➑️) Arrived a new car! πŸš™πŸ’¨ 
-697358592 (Right ➑️) I'm the fist, I allow the Right ➑️ direction 🟒 🟒 
-697358592 (Right ➑️) I'll pass the bridge in a row, and now I'm the last 🟒 
-697358592 (Right ➑️) I passed the bridge 🟒 
-697358592 (Right ➑️) I was the last, the bridge is empty 🟑 

Caso 2

EjecuciΓ³n: ./main 7 6 2 3

Resultado:

Parameters set at: East cars: 7, West cars: 6, East lambda: 2, West lambda: 3
Before Thread
===================Left Times ============== 
Time = 3.156758 
Time = 6.247203 
Time = 9.495758 
Time = 9.543585 
Time = 17.531501 
Time = 25.652481 
===================Right Times ============== 
Time = 3.773602 
Time = 7.449789 
Time = 10.267353 
Time = 13.422997 
Time = 15.114030 
Time = 19.688628 
Time = 19.851628 
===================Total Times and Direction ==============
Time = 3.156758 Direction = -1 
Time = 3.773602 Direction = 1 
Time = 6.247203 Direction = -1 
Time = 7.449789 Direction = 1 
Time = 9.495758 Direction = -1 
Time = 9.543585 Direction = -1 
Time = 10.267353 Direction = 1 
Time = 13.422997 Direction = 1 
Time = 15.114030 Direction = 1 
Time = 17.531501 Direction = -1 
Time = 19.688628 Direction = 1 
Time = 19.851628 Direction = 1 
Time = 25.652481 Direction = -1 


 ** BEGIN PROCESS TO PASS THE BRIDGE ** 


-993585408 (Left  ⬅️) Arrived a new car! πŸš™πŸ’¨ 
-993585408 (Left  ⬅️) I'm the fist, I allow the Left  ⬅️ direction 🟒 🟒 
-993585408 (Left  ⬅️) I'll pass the bridge in a row, and now I'm the last 🟒 

-1001978112 (Right ➑️) Arrived a new car! πŸš™πŸ’¨ 
-1001978112 (Right ➑️) I'll wait because bridge is in use πŸ”΄ 

-1010370816 (Left  ⬅️) Arrived a new car! πŸš™πŸ’¨ 
-1010370816 (Left  ⬅️) It's my same direction 🟒 
-1010370816 (Left  ⬅️) I'll pass the bridge in a row, and now I'm the last 🟒 

-1018763520 (Right ➑️) Arrived a new car! πŸš™πŸ’¨ 
-1018763520 (Right ➑️) I'll wait because bridge is in use πŸ”΄ 
-993585408  (Left  ⬅️) I passed the bridge 🟒 

-1027156224 (Left  ⬅️) Arrived a new car! πŸš™πŸ’¨ 
-1027156224 (Left  ⬅️) It's my same direction 🟒 
-1027156224 (Left  ⬅️) I'll pass the bridge in a row, and now I'm the last 🟒 

-1035548928 (Left  ⬅️) Arrived a new car! πŸš™πŸ’¨ 
-1035548928 (Left  ⬅️) It's my same direction 🟒 
-1035548928 (Left  ⬅️) I'll pass the bridge in a row, and now I'm the last 🟒 

-1043941632 (Right ➑️) Arrived a new car! πŸš™πŸ’¨ 
-1043941632 (Right ➑️) I'll wait because bridge is in use πŸ”΄ 
-1010370816 (Left  ⬅️) I passed the bridge 🟒 

-1052334336 (Right ➑️) Arrived a new car! πŸš™πŸ’¨ 
-1052334336 (Right ➑️) I'll wait because bridge is in use πŸ”΄ 

-1060727040 (Right ➑️) Arrived a new car! πŸš™πŸ’¨ 
-1060727040 (Right ➑️) I'll wait because bridge is in use πŸ”΄ 
-1027156224 (Left  ⬅️) I passed the bridge 🟒 
-1035548928 (Left  ⬅️) I passed the bridge 🟒 
-1035548928 (Left  ⬅️) I was the last, the bridge is empty 🟑 

-1001978112 (Right ➑️) Now is my turn, I'll prepare to pass 🟑 
-1001978112 (Right ➑️) I'm the fist, I allow the Right ➑️ direction 🟒 🟒 
-1001978112 (Right ➑️) I'll pass the bridge in a row, and now I'm the last 🟒 
-1018763520 (Right ➑️) Now is my turn, I'll prepare to pass 🟑 
-1018763520 (Right ➑️) It's my same direction 🟒 
-1043941632 (Right ➑️) Now is my turn, I'll prepare to pass 🟑 
-1060727040 (Right ➑️) Now is my turn, I'll prepare to pass 🟑 
-1060727040 (Right ➑️) It's my same direction 🟒 
-1018763520 (Right ➑️) I'll pass the bridge in a row, and now I'm the last 🟒 
-1052334336 (Right ➑️) Now is my turn, I'll prepare to pass 🟑 
-1052334336 (Right ➑️) It's my same direction 🟒 
-1052334336 (Right ➑️) I'll pass the bridge in a row, and now I'm the last 🟒 
-1060727040 (Right ➑️) I'll pass the bridge in a row, and now I'm the last 🟒 
-1043941632 (Right ➑️) It's my same direction 🟒 
-1043941632 (Right ➑️) I'll pass the bridge in a row, and now I'm the last 🟒 

-1069119744 (Left  ⬅️) Arrived a new car! πŸš™πŸ’¨ 
-1069119744 (Left  ⬅️) I'll wait because bridge is in use πŸ”΄ 

-1077512448 (Right ➑️) Arrived a new car! πŸš™πŸ’¨ 
-1077512448 (Right ➑️) It's my same direction 🟒 
-1077512448 (Right ➑️) I'll pass the bridge in a row, and now I'm the last 🟒 

-1085905152 (Right ➑️) Arrived a new car! πŸš™πŸ’¨ 
-1085905152 (Right ➑️) It's my same direction 🟒 
-1085905152 (Right ➑️) I'll pass the bridge in a row, and now I'm the last 🟒 
-1001978112 (Right ➑️) I passed the bridge 🟒 
-1018763520 (Right ➑️) I passed the bridge 🟒 
-1052334336 (Right ➑️) I passed the bridge 🟒 
-1060727040 (Right ➑️) I passed the bridge 🟒 
-1043941632 (Right ➑️) I passed the bridge 🟒 
-1077512448 (Right ➑️) I passed the bridge 🟒 
-1085905152 (Right ➑️) I passed the bridge 🟒 
-1085905152 (Right ➑️) I was the last, the bridge is empty 🟑 


-1094297856 (Left  ⬅️) Arrived a new car! πŸš™πŸ’¨ 
-1069119744 (Left  ⬅️) Now is my turn, I'll prepare to pass 🟑 
-1069119744 (Left  ⬅️) I'm the fist, I allow the Left  ⬅️ direction 🟒 🟒 
-1069119744 (Left  ⬅️) I'll pass the bridge in a row, and now I'm the last 🟒 
-1094297856 (Left  ⬅️) I'm the fist, I allow the Left  ⬅️ direction 🟒 🟒 
-1069119744 (Left  ⬅️) I passed the bridge 🟒 
-1069119744 (Left  ⬅️) I was the last, the bridge is empty 🟑 

-1094297856 (Left  ⬅️) I'll pass the bridge in a row, and now I'm the last 🟒 
-1094297856 (Left  ⬅️) I passed the bridge 🟒 
-1094297856 (Left  ⬅️) I was the last, the bridge is empty 🟑 





_ end line _

About

Create threads that attempt to cross a bridge if it is empty based on direction. The output is in the console with pretty prints.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%