-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2d4b3a8
Showing
12 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>LabSemana2</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.8 |
Submodule Lab2Infracomp
added at
6277e6
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package maxFila; | ||
|
||
public class Maximo { | ||
|
||
private int contador, maximo, nThreads, identificador; | ||
|
||
/** | ||
* Método constructor de la clases | ||
* @param numT | ||
*/ | ||
public Maximo (int numT) { | ||
nThreads = numT; | ||
maximo=0; | ||
contador=0; | ||
identificador=0; | ||
} | ||
|
||
public int darMaximo() { | ||
return maximo; | ||
} | ||
|
||
public int darIdentificador() { | ||
return identificador; | ||
} | ||
|
||
|
||
|
||
public synchronized boolean anotar (int n, int pId) { | ||
|
||
/** | ||
* Se revisa si se supera al máximo que se tenía y se hacen las respectivas asignaciones | ||
*/ | ||
|
||
if (n > maximo) { | ||
maximo = n ; | ||
identificador = pId+1; | ||
} | ||
|
||
/** | ||
* Se revisa que el último Thread se haya ejecutado para poder imprimir en la consola | ||
*/ | ||
|
||
if(++contador == nThreads) return true; | ||
else return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package maxFila; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
public class T extends Thread { | ||
|
||
|
||
private final static int DIM = 4; | ||
private final static int LIM = 500; | ||
private static int[][] matriz = new int[DIM][DIM]; | ||
|
||
private static Maximo maxGlobal; | ||
|
||
private int id = 0 ; | ||
private int maxFila = -1; | ||
|
||
|
||
public static void inicializarMAtriz() { | ||
|
||
for(int i = 0; i < DIM; i++) { | ||
for(int j = 0; j < DIM; j++) { | ||
matriz[i][j] = ThreadLocalRandom.current().nextInt(0, LIM); | ||
} | ||
} | ||
} | ||
|
||
|
||
public static void imprimirMatriz() { | ||
|
||
for(int i = 0; i < DIM; i++) { | ||
for(int j = 0; j < DIM; j++) { | ||
System.out.print(matriz[i][j] + "\t"); | ||
} | ||
System.out.println(); | ||
} | ||
System.out.println("******************************"); | ||
} | ||
|
||
/** | ||
* Constructor para inicializar el Thread | ||
* @param pId | ||
*/ | ||
public T (int pId) { | ||
id = pId ; | ||
} | ||
|
||
|
||
public void run () { | ||
|
||
|
||
for(int j = 0; j < DIM; j++){ | ||
if(this.maxFila < matriz[this.id][j]) this.maxFila = matriz[this.id][j]; | ||
} | ||
|
||
|
||
if(maxGlobal.anotar(this.maxFila, this.id)) | ||
System.out.println("Valor máximo: " + maxGlobal.darMaximo() + " - Localizado por el thread: " + maxGlobal.darIdentificador()); | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
|
||
System.out.println("*************************"); | ||
System.out.println("******** Matriz ******** "); | ||
System.out.println("*************************"); | ||
|
||
inicializarMAtriz(); | ||
imprimirMatriz(); | ||
|
||
int numThreads = DIM; | ||
maxGlobal = new Maximo(numThreads); | ||
|
||
for (int i = 0; i < numThreads; i++) | ||
new T (i).start(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package pasarela; | ||
|
||
public class Pasarela{ | ||
|
||
private static int caminandoDir0 = 0; | ||
|
||
private static int caminandoDir1 = 0; | ||
|
||
public synchronized void entrar (int dir) { | ||
|
||
if (dir == 0) { | ||
while (caminandoDir1>0) { | ||
try { | ||
wait(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
caminandoDir0++; | ||
System.out.println("Entró uno en la dirección 0"); | ||
} | ||
|
||
else { | ||
while (caminandoDir0>0) { | ||
try { | ||
wait(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
caminandoDir1++; | ||
System.out.println("Entró uno en la dirección 1"); | ||
} | ||
|
||
} | ||
|
||
|
||
public void caminar () { | ||
try { | ||
Thread.sleep(5); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public synchronized void salir() { | ||
if (caminandoDir0 == 0) { | ||
caminandoDir1--; | ||
System.out.println("Salió uno en la dirección 1"); | ||
|
||
if (caminandoDir1 == 0) { | ||
notifyAll(); | ||
} | ||
else { | ||
notify(); | ||
} | ||
} | ||
else { | ||
caminandoDir0--; | ||
System.out.println("Salió uno en la dirección 0"); | ||
if (caminandoDir0 == 0) { | ||
notifyAll(); | ||
} | ||
else { | ||
notify(); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package pasarela; | ||
|
||
public class Persona extends Thread{ | ||
|
||
private int idPersona; | ||
private int dir; | ||
|
||
public static Pasarela pista; | ||
|
||
public Persona (int idPersona, int dir) { | ||
this.dir=dir; | ||
this.idPersona=idPersona; | ||
} | ||
|
||
|
||
public void run(){ | ||
pista.entrar(this.dir); | ||
pista.caminar(); | ||
pista.salir(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
pista = new Pasarela(); | ||
|
||
for (int i = 0; i < 20; i++) | ||
new Persona(i,(int)(Math.random()*2)).start(); | ||
|
||
} | ||
|
||
|
||
} |