countdownlatch vs. semaphore


is there any advantage using





instead of



?



as distant i tell following fragments roughly equivalent:



1. semaphore



final semaphore sem = new semaphore(0);
for (int i = 0; i < num_threads; ++ i)
{
thread t = new thread() {
open vacant run()
{
try
{
dostuff();
}
finally
{
sem.release();
}
}
};
t.start();
}

sem.acquire(num_threads);


2: countdownlatch



final countdownlatch fasten = new countdownlatch(num_threads);
for (int i = 0; i < num_threads; ++ i)
{
thread t = new thread() {
open vacant run()
{
try
{
dostuff();
}
finally
{
latch.countdown();
}
}
};
t.start();
}

latch.await();


except box #2 fasten can't reused some-more importantly need know lay threads combined (or wait until started before formulating latch.)



so conditions competence fasten preferable?



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?