Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I'm 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 wouldn't 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 doesn't work,

it is starting to frustrate me :-\ .

 

Is there a basic "guideline" I can use?

 

I'm currently looking into a circular buffer.

If I fail again I'll post the code of it here,

so you can give some advice if you want.

Posted

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 I'm using so you know what I'm 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 I'm doing wrong?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...