Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: OriOn on February 11, 2003, 08:52 PM

Title: Threaded Bot
Post by: OriOn on February 11, 2003, 08:52 PM
Hello all

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

Sorry my english is poor

OriOn-
Title: Re: Threaded Bot
Post by: Yoni on February 12, 2003, 02:14 AM
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.
Title: Re: Threaded Bot
Post by: Brand.X on February 12, 2003, 10:17 AM
One advantage of multithreading, is if you get stuck in an infinite loop it won't freeze your program. ;)
Title: Re: Threaded Bot
Post by: tA-Kane on February 12, 2003, 10:38 AM
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.
Title: Re: Threaded Bot
Post by: Skywing on February 12, 2003, 12:58 PM
QuoteOne advantage of multithreading, is if you get stuck in an infinite loop it won't freeze your program. ;)
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.
Title: Re: Threaded Bot
Post by: Adron on February 12, 2003, 01:53 PM
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).
Title: Re: Threaded Bot
Post by: Skywing on February 12, 2003, 03:22 PM
QuoteAnother 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).
Enjoy QueueUserAPC and IO completion.
Title: Re: Threaded Bot
Post by: Eibro on February 12, 2003, 05:53 PM
"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.
Title: Re: Threaded Bot
Post by: Adron on February 12, 2003, 06:25 PM
QuoteEnjoy QueueUserAPC and IO completion.

Hmm, not quite clear to me how those will make your bot respond while it's processing this:
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));
  }

edit: code tags
Title: Re: Threaded Bot
Post by: Skywing on February 12, 2003, 06:28 PM
QuoteHmm, not quite clear to me how those will make your bot respond while it's processing this:
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));
  }

edit: code tags
Naturally you use QueueUserWorkItem to execute that.

Why would a bot be graphing fractals, anyway? :P
Title: Re: Threaded Bot
Post by: Adron on February 12, 2003, 06:31 PM
QuoteNaturally you use QueueUserWorkItem to execute that.

Why would a bot be graphing fractals, anyway? :P

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? ;)
Title: Re: Threaded Bot
Post by: iago on February 12, 2003, 06:37 PM
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.

ftp://Guest:[email protected]:665/windows.chm

I'm not positive about the filename, but it should be somewhere on there anyway :)