Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grageda - Farias - Ferrero (TP11 Threads) #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ClaseHilos/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
//_5Mutex.Excecute();

//6- Uso de lock
_6lock.Excecute();
//_6lock.Excecute();

// Solucion de las 3 tareas.
Solution.Excecute();



77 changes: 65 additions & 12 deletions ClaseHilos/solution.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System.Net;
using System.Runtime.InteropServices;

namespace ClaseHilos
{
internal class Producto
Expand Down Expand Up @@ -25,24 +28,74 @@ internal class Solution //reference: https://learn.microsoft.com/en-us/dotnet/cs
new Producto("Gorra", 16, 10)
};

static int precio_dolar = 500;

static void Tarea1()
static int precio_dolar = 500;
static readonly object locker = new object();
static void Tarea1()
{
throw new NotImplementedException();
}
lock (locker)
{
foreach (Producto producto in productos)
{
producto.CantidadEnStock += 10;
}
}
}
static void Tarea2()
{
throw new NotImplementedException();
lock (locker)
{
precio_dolar = 876;
}
}
static void Tarea3()
{
throw new NotImplementedException();
}
decimal precio_total = 0;
lock (locker)
{
foreach (Producto producto in productos)
{
decimal precio_total_por_producto = producto.CantidadEnStock * precio_dolar * producto.PrecioUnitarioDolares;
Console.WriteLine($"{producto.Nombre} - Nueva cantidad en stock: {producto.CantidadEnStock} "
+ $",precio actualizado en pesos de cada unidad: ${producto.PrecioUnitarioDolares * precio_dolar}"
+ $"y precio total: ${(precio_total_por_producto)}");
precio_total += precio_total_por_producto;

}
}
Console.WriteLine($"Precio total general: ${precio_total}");
}

static void TareaEvolutiva()
{
lock (locker)
{
foreach (Producto p in productos)
{
p.PrecioUnitarioDolares = p.PrecioUnitarioDolares * 110 / 100;
}
}
}

internal static void Excecute()
internal static void Excecute()
{
throw new NotImplementedException();
}
}
Thread task1 = new Thread(new ThreadStart(Tarea1));
Thread task2 = new Thread(new ThreadStart(Tarea2));
Thread task3 = new Thread(new ThreadStart(Tarea3));
Thread taskEvolutiva = new Thread(new ThreadStart(TareaEvolutiva));

task1.Start();
task2.Start();
taskEvolutiva.Start();

task1.Join();
task2.Join();
taskEvolutiva.Join();


task3.Start();
task3.Join();


}
}
}