Hashing a file with different hashes in one go

Arokh

Well-known member
Joined
Apr 11, 2006
Messages
124
Hi,

Im currently writing a application which calculates different hashes.
Every hash I "have" has inheritet the HashAlgorithm class and now
I want to use them to calculate those hashes.

And I want it to be calculated as fast as possible.
At first I thought it wouldnt be so hard to do so,
but I guess I was wrong.

Since I have 4 cores I wanted to make 4 threads.
Each thread would be responsible for calculating a hash.

Then I have a main loop which reads from the file,
then "passes" the data onto the threads,
and tell it to calculate the next part of the hash.

But I keep on having something like synchronisation problems.
And everytime I try to rewrite it I end up with something that doesnt work,
it is starting to frustrate me :-\ .

Is there a basic "guideline" I can use?

Im currently looking into a circular buffer.
If I fail again Ill post the code of it here,
so you can give some advice if you want.
 
I think I almost got it with the Circular Buffer idea based on:
http://en.wikipedia.org/wiki/Circular_buffer#Absolute_indices

But somehow everytime it appends data from previous streamreads,
and if I try to fix it I get an endless loop.

Here is the code Im using so you know what Im talking about:
http://pastebin.com/f690fd7b2 (CSharp code tag seems to be a little broken)

To start it, copy paste of the code should do.

The testcode which shows my problem (Program class),
creates a testfile ("Test.txt") filled with a pattern.
Then 4 readers which read from the circular buffer put everything they get into a new file "Test{ReaderIndex}.txt".

Now the resulting files should be exactly the same, but they are 32kb bigger.
(2 Blocks in the Circular Buffer)

Has anybody an idea what Im doing wrong?
 
Back
Top