in reply to Re: Re: Non-blocking pings on Win32
in thread Non-blocking pings on Win32
As for the changes NetWallah made above, they do make sense and I should probably have included them. The real code I use in production is a bit different:
IP Addresses are pulled from a database. Since I don't want to use up a lot of memory putting all 5000+ entries into an array, I actually spawn the threads first, and then slowly feed entries into the Queue as I read them from the database.
I needed a "while (1)" because there are times in the thread's life when the queue is empty but it should wait rather than exiting, such as when it's first created. My production code has a shared flag indicating whether all entries have been loaded into the queue, and then each thread will "sleep 1; next;" or "last;" based on the status of that shared flag.
Also, rather than have a "result" array in memory holding thousands of results to print afterwards, each thread maintains an open connection to the database during its life, and uses it to store the results.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Non-blocking pings on Win32
by Ninthwave (Chaplain) on Dec 12, 2003 at 12:00 UTC | |
by meetraz (Hermit) on Dec 15, 2003 at 20:32 UTC | |
|
Re: Re: Re: Re: Non-blocking pings on Win32
by Ninthwave (Chaplain) on Jan 13, 2004 at 10:03 UTC |