Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Default to starting no threads.
Hopefully this helps the spectests.
  • Loading branch information
jnthn committed Jul 12, 2013
1 parent 125f458 commit e587d79
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/vm/jvm/core/Threading.pm
Expand Up @@ -150,9 +150,13 @@ my class ThreadPoolScheduler {
# management of the pool size.
has Mu $!outstanding;

# Have we started any threads yet?
has int $!started_any;

# Adds a new thread to the pool, respecting the maximum.
method !maybe_new_thread() {
if $!thread_start_semaphore.'method/tryAcquire/(I)Z'(1) {
$!started_any = 1;
Thread.start(:app_lifetime, {
loop {
my Mu $task := $interop.javaObjectToSixmodel($!queue.take());
Expand All @@ -163,9 +167,7 @@ my class ThreadPoolScheduler {
}
}

submethod BUILD(:$initial_threads = 1, :$max_threads = 4) {
die "Must have at least one thread pool thread"
if $initial_threads < 1;
submethod BUILD(:$initial_threads = 0, :$max_threads = 4) {
die "Initial thread pool threads must be less than or equal to maximim threads"
if $initial_threads > $max_threads;
$!queue := LinkedBlockingQueue.'constructor/new/()V'();
Expand All @@ -176,7 +178,7 @@ my class ThreadPoolScheduler {

method schedule(&code) {
self!maybe_new_thread()
if $!outstanding.incrementAndGet() > 1;
if !$!started_any || $!outstanding.incrementAndGet() > 1;
$!queue.add($interop.sixmodelToJavaObject(&code));
}

Expand Down

0 comments on commit e587d79

Please sign in to comment.