Valhalla Legends Forums Archive | Battle.net Bot Development | Threaded Bot

AuthorMessageTime
OriOn
Hello all

What brings the thread-programmation of a bot ?
And which part do u threaded ?

Sorry my english is poor

OriOn-
February 12, 2003, 2:52 AM
Yoni
Thread programmation sure is fun, but it is usually unneeded.
For example, BinaryChat (*cough*) can run many profiles (as many as your RAM allows) each with 2-3 sockets and do this all in one thread. This is achieved by using I/O completion to be notified of Winsock events, instead of kernel event handles or windows messages. (Requires Winsock 2.0.)

The only times you would want to use multithreading is when:
1) The API doesn't allow otherwise.
2) You want to optimize your application (usually a big server) for dual- or multi-processor machines.
February 12, 2003, 8:14 AM
Brand.X
One advantage of multithreading, is if you get stuck in an infinite loop it won't freeze your program. ;)
February 12, 2003, 4:17 PM
tA-Kane
No, it'll just freeze that thread.

Hopefully, if that happens, hopefully you've implemented the API call to kill and delete that thread. Otherwise, you've a rogue thread wasting resources.
February 12, 2003, 4:38 PM
Skywing
[quote]One advantage of multithreading, is if you get stuck in an infinite loop it won't freeze your program. ;)
[/quote]
Actually, you'll probably have to use some kind of synchronization mechanism to protect any real code, so the odds are that your program would still lock.
February 12, 2003, 6:58 PM
Adron
Another advantage is if you have tasks that may take a while to execute and you want other tasks to preempt them. By using threads you won't have to write your own code for that (that implements threads).
February 12, 2003, 7:53 PM
Skywing
[quote]Another advantage is if you have tasks that may take a while to execute and you want other tasks to preempt them. By using threads you won't have to write your own code for that (that implements threads).[/quote]
Enjoy QueueUserAPC and IO completion.
February 12, 2003, 9:22 PM
Eibro
"Programming C++ Applications for Microsoft Windows" by Jeff Richter has a bunch of info on when/when not to thread your applications; you usually thread when it makes sense to thread :). I'm sure you can find an ebook around somewhere, many people have it.
February 12, 2003, 11:53 PM
Adron
[quote]
Enjoy QueueUserAPC and IO completion.[/quote]

Hmm, not quite clear to me how those will make your bot respond while it's processing this:
[code]
double x, y;
double limit = 100000;
int i;
complex<double> a(-0.74543, 0.11301);
for(x = -2; x < 2; x += 0.001)
 for(y = -2; y < 2; y += 0.001) {
   complex<double> c(x, y);
   for(i = 1; i < 10000000; i++) {
     c *= c;
     c += a;
     if(c.real()*c.real() + c.imag()*c.imag() > limit)
       break;
   }
   SetPixel((x + 2) * 1000, (y + 2) * 1000, ColorMap(i));
 }
[/code]

edit: code tags
February 13, 2003, 12:25 AM
Skywing
[quote]

Hmm, not quite clear to me how those will make your bot respond while it's processing this:
[code]
double x, y;
double limit = 100000;
int i;
complex<double> a(-0.74543, 0.11301);
for(x = -2; x < 2; x += 0.001)
 for(y = -2; y < 2; y += 0.001) {
   complex<double> c(x, y);
   for(i = 1; i < 10000000; i++) {
     c *= c;
     c += a;
     if(c.real()*c.real() + c.imag()*c.imag() > limit)
       break;
   }
   SetPixel((x + 2) * 1000, (y + 2) * 1000, ColorMap(i));
 }
[/code]

edit: code tags[/quote]
Naturally you use QueueUserWorkItem to execute that.

Why would a bot be graphing fractals, anyway? :P
February 13, 2003, 12:28 AM
Adron
[quote]
Naturally you use QueueUserWorkItem to execute that.

Why would a bot be graphing fractals, anyway? :P[/quote]

QueueUserWorkItem would require you to have multiple threads though :P

And regarding fractals, wouldn't that be pretty nice to have as a background for the channel? ;)
February 13, 2003, 12:31 AM
iago
[quote]"Programming C++ Applications for Microsoft Windows" by Jeff Richter has a bunch of info on when/when not to thread your applications; you usually thread when it makes sense to thread :). I'm sure you can find an ebook around somewhere, many people have it.[/quote]

ftp://Guest:Guest@iago.no-ip.com:665/windows.chm

I'm not positive about the filename, but it should be somewhere on there anyway :)
February 13, 2003, 12:37 AM

Search