First big PITA in reallife D project
Fawzi Mohamed
fawzi at gmx.ch
Tue Oct 19 13:24:46 PDT 2010
On 19-ott-10, at 19:17, Andrei Alexandrescu wrote:
> On 10/19/10 11:07 CDT, FeepingCreature wrote:
>> On 19.10.2010 13:33, Stephan wrote:
>>> BUT it wont work like that. AFTER i stopped all other threads some
>>> strange behavior of druntime makes every creation of an
>>> InternetAddress instance (internally trying to resolve host)
>>> impossible (throws an exception). Additionally even if the Internet
>>> Addresses were created upfront the TcpSockets wont connect but
>>> throw.
>>
>> Terminating threads has always been iffy in D.
>
> Terminating threads has always been iffy in all languages that use
> native threads. I've discussed with Sean a couple of times about
> ways to define a little protocol and API for orderly thread
> termination. We need something like a callback mechanism -
> atShutdown().
As feep wrote using thread pools is often better.
With D1/tango one can use blip (whose release is hopefully just a few
days away) it becomes very nice to do.
Unfortunately this is not for Stephan, as most likely it will not work
on windows, because I used and developed it only on
mac/linux, and windows will require some porting.
Anyway checking several addresses in parallel becomes simply:
import blip.parallel.smp.PLoopHelpers;
import blip.io.Socket;
//...
foreach(addr;pLoopArray(adressesToCheck){
auto s=BasicSocket(addr,"80");
// do stuff
}
and this will use optimally all processors of your computer, and will
use libev to never block waiting for input...
Also making a server is not so difficult as shown by http://github.com/fawzi/blip/blob/master/tests/EchoServer.d
the checking operation can spawn new tasks without problems.
Fawzi
More information about the Digitalmars-d
mailing list