Ignore:
Timestamp:
2013-12-18T12:53:06+13:00 (10 years ago)
Author:
jmt12
Message:

opps.. left one join behind. fixed now, and added comment about the lingering problem of the main thread exiting while child threads still exist (prompting the 'a thread exited while X threads were still running' warning message)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/tdb-edit/trunk/src/perllib/SocketsSwimmingThreadPoolServer.pm

    r28775 r28776  
    22# @url    https://github.com/macnod/DcServer
    33# @readme http://donnieknows.com/blog/perl-sockets-swimming-thread-pool
     4
     5# One lurking issue with the ThreadPoolServer is that several threads don't get
     6# a chance to return before the server shuts down. In a perfect world they'd
     7# all get a chance to notice the 'stop' flag has been set and thusly
     8# stop. However, it is only by chance this happens as most will spend most of
     9# their lives either blocked listening to a socket (accept_requests) or blocked
     10# waiting to dequeue a message (request_handlers). Possible solutions, such as
     11# interupts, have problems of their own - interrupting mid-read of a socket
     12# could be bad.  Since this is non-fatal, and non-trivial to fix, I'm just
     13# leaving it for now.
    414
    515package SocketsSwimmingThreadPoolServer;
     
    2838      LocalPort => $param{port} || 8191},
    2939    thread_count => $param{thread_count} || 10,
    30     main_yield => $param{main_yield} || 5,
     40    main_yield => $param{main_yield} || 1,
    3141    main_cb => $param{main_cb} || sub {},
    3242    done_cb => $param{done_cb} || sub {},
     
    6878sub stop
    6979{
    70   my $self= shift;
     80  my $self = shift;
    7181  $stop= 1;
    7282}
     
    94104    if (!defined $lsocket || !$lsocket)
    95105    {
    96       print STDERR "Error! Can't create listerner socket so server can't start (trying again in 1 second). Error message: \"" . $! . "\"\n";
     106      print STDERR "Warning! Can't create listener socket so server can't start (trying again in 1 second).\n";
     107      print STDERR "Error message: \"" . $! . "\"\n\n";
    97108      sleep(1);
    98109    }
     
    162173    $closed_queue->enqueue($n);
    163174  }
    164 
    165   # Shouldn't join() detached threads?
    166   # Properly rejoin thread
    167   # Newer versions of module thread
    168   #if (defined $self->can('is_joinable'))
    169   #{
    170   #  print "[debug] using newer thread->is_joinable... ";
    171   #  if ($self->is_joinable())
    172   #  {
    173   #    $self->join();
    174   #    print "joined\n";
    175   #  }
    176   #  else
    177   #  {
    178   #    print "not joinable\n";
    179   #  }
    180   #}
    181   #else
    182   #{
    183   #  print "[debug] using newer thread->is_detached... ";
    184   #  my $thread = threads->self();
    185   #  if (!$thread->is_detached())
    186   #  {
    187   #    $thread->join();
    188   #    print "joined\n";
    189   #  }
    190   #  else
    191   #  {
    192   #    print "not detached\n";
    193   #  }
    194   #}
    195175}
    196176
Note: See TracChangeset for help on using the changeset viewer.