|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: Apr 2005
Messaggi: 93
|
[JAVA] thread: start contemporaneo
mi spiego meglio. io ho già esteso la classe Thread e modificato il metodo tun in modoc he fa quello che voglio io.
nella classe Test dove ho il main ho creato e fatto partire i tre processi new Thread("nomeThread1").start(); new Thread("nomeThread2").start(); il problema è che questi tre processi non partono in contemporanea... (almeno così so io) è l'esercizio mi chiede di implementare un abitro coordina l'inizio del gioco garantendo che i giocatori possano iniziare il gioco contemporaneamente
__________________
Inspiron 9400 - centrino duo 2 T7200 - HD 100 Gb 7200 Rpm - 2 Gb 667 Mhz - nVidia 7900 Gs 256 Mb - 17" Truelife - Windows Xp professional SP3 |
![]() |
![]() |
![]() |
#2 | ||
Senior Member
Iscritto dal: Oct 2006
Città: Roma
Messaggi: 1383
|
Quote:
Quote:
|
||
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Oct 2006
Città: Roma
Messaggi: 1383
|
effettivamente questa via é preferibile rispetto al sistema che ho suggerito io, il quale richiede piu lavoro perché oltre alla gestione degli spurious wakeups bisogna anche stare attenti all'eventualitá che notifyAll venga chiamata prima che entrambi i thread si siano bloccati sulla wait.
|
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Oct 2006
Città: Roma
Messaggi: 1383
|
ad esempio, questa soluzione é errata:
Codice:
final Object start = new Object(); volatile boolean starting = false; . . . new Thread("Thread1") { @Override public void run() { synchronized (start) { while (!starting) { start.wait(); } } } }.start(); new Thread("Thread2") { @Override public void run() { synchronized (start) { while (!starting) { start.wait(); } } } }.start(); starting = true; start.notifyAll(); |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 14:26.