[quoted text, click to view] On Jun 9, 4:00 pm, Marc Gravell <marc.grav...@gmail.com> wrote:
> It is hard to say without some code... but for what it is worth,
> starting N threads seems overkill anyways... unless you are expecting
> high latency (e.g. remote comms), why not have 1 thread per CPU (or
> some factor there-of)? With disk-IO-bound operations, even with this
> you are likely to swamp the HDD.
The setting for how many files to convert simultaneously is
adjustable, as is the amount of time the threads sleep. I want the
application to work so that you can convert files in batch and push as
many files as can be handled, as determined by the user. On my
machine, which has two processor cores, if I convert four files
simultaneously, making each thread sleep 1 ms, the system is
responsive, and the files convert nearly as fast as if they were
converted sequentially. If I want to walk away from my computer and
let it work, I set it to sleep no time at all, and the system becomes
unresponsive until the task is done; however, by my estimates, the
time taken for the four files to convert is noticeably faster.
[quoted text, click to view] > It isn't clear how you are initialising your threads; I'd guess that
> you missed something when synchronising; can you post any code of how
> the threads are started, and how they get their "what to do"?
Here's a snippet. The method that gets put on the thread is from an
object of the class ConvertFile. I have an array of ConvertFile
objects. I iterate over the number of threads available for use, and
start them with the object in the array at the current index. Each
object is passed a string to a file to convert, and that's all the
thread needs. The task is "embarrassingly parallel" in this regard.
The thread accesses the DLL and works on converting the file.
for ( int i=0; ... /* loop over number of threads user specifies */ )
{
cvf[i] = new ConvertFile();
cvf[i].InFile = (string)listBox1.Items[i]; // Pass in input
file path
tsCvf[i] = new ThreadStart( cvf[i].FromFormatX );
tCvf[i] = new Thread( tsCvf[i] );
Thread.Sleep(100); // This keeps it from crashing... ?
}