threads

Technical discussion about the NMDC and <a href="http://dcpp.net/ADC.html">ADC</A> protocol. The NMDC protocol is documented in the <a href="http://dcpp.net/wiki/">Wiki</a>, so feel free to refer to it.

Moderator: Moderators

Locked
dieselmachine
Posts: 36
Joined: 2003-01-19 22:22
Location: Rochester, NY, USA
Contact:

threads

Post by dieselmachine » 2003-06-26 10:09

I know almost nothing about threading. However, this is what little i do know (or at least i think i know). via threading, i can 'stop' a method partway through, and the rest of the program (provided it doesnt need any info from the thread) can continue. Like, if i was doing some downloading on direct connect, i could call a thread somehow to calculate the millionth digit of pi (which might take a little while), but while it's chugging away, i can keep doing shit with the program. Is this more or less right?

Anyway, provided that im not misunderstanding the point of a thread, i need to create one for my program which is started at runtime, and essentially runs independant of the program. I dont know where to start though. How do i make something 'threaded'?

I'm sorry if this question is retarded, i think im just missing something simple. I've done some looking around, but havent found anything useful to what im trying to do.

sarf
Posts: 382
Joined: 2003-01-24 05:43
Location: Sweden
Contact:

Post by sarf » 2003-06-26 10:41

Yes, you are correct (although my teachers at the university would probably cry in their whiskey if you asked them).

I would recommend the Thread.h (don't think there is a Thread.cpp) in the client part of DC++ - in essence, this class wraps all the ugly thread code and gives you a nice, fresh, clean and good-smelling class to inherit and do cool threaded stuff with. I would let myself be "inspired" by it (i.e. copy it and give credit to arnetheduck on a credits page hidden right next to the pictures of my dog being ill).

To make something threaded, inherit the Thread class (as public, I think), implement the int run() method and when you wish to start a thread, create an object of your class and run its start() method. It really is as simple as that.

Sarf
---
As the Euclideans would have it, irrationality is the square root of all evil.

Locked