Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C MFC Threading
In my MFC dialog based application there are 2 parent threads and inside the parent thread there are 3 child threads and these are synchronized using CEvent-- SetEvent() and ResetEvent().
The input file is readed as blocks of 16 char.Shared buffer is used for storing the blocks.
 
child thread1 -- used for read a block(16 char) from file1
child thread2 -- used to perform some task on block readed by thread1
chikd thread3 -- used to write the modified block to file2
 
These three child thread are in while loop until block > 0.
 
The child thread1 sets event for child thread2 and child thread2 sets event for child thread3.
 
The run time performance of the application is very poor for the large files. How can I increase the performance as the application runs very slow?
Posted 1-Apr-10 2:27am
Edited 27-Apr-10 9:59am
Moak11.4K
v2
Page 1 of 3

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Pure, of course:
you have lost the multithreading processing by this technique,
since your threads are working nonparallel... Smile | :)

I would solve it like following:

0. Control the file access by a critical section (for thread 1 und 3)

1. Allocate a protected by a second critical section the whole-sized buffer

2. Control the "clusters" of the buffer in a cluster list protected by a third critical section

2a. The first thread read a block by block from the file in its loop and
2aa. fill the buffer by the read cluster
2ab. make an entry in the list with the flag "ReadyToModify = true, BlockOffsetInBuffer = x, BlockLengthInBuffer = y"

2b. The second thread iterate the list to find the next entry marked by "ReadyToModify = 1"
2ba. read the cluster from the buffer to a local buffer
2bb. modify the local buffer
2bc. fill the buffer by local modified cluster
2bd. set the list entry flag "ReadyToSave = 1"

2c. The third thread iterate the list to find the next entry marked by "ReadyToSave = 1"
2ca. read the cluster from the buffer to a local buffer
2cb. save the local buffer in to the file
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 56

First: when talking performance, you need to show numbers. One can only guess _why_ the app is slow.
 
However, one figure that jumps out of your question is the number 16: "read 16 characters from file1"...
 
File access is amongst the most expensive in a program: disk latency etc... Your program seems to be IO-bound. You could try to figure out whether the bottleneck is the file-IO; I assume the answer will be "yes".
 
Assuming file-IO is the bottleneck, try to limit it: read bigger chunks at a time, thus ruling out the disk-read overhead.
 
And: don't expect magic: 'larger' files will take 'larger' amounts of time. The question is if it's within reason.
  Permalink  
Page 1 of 3
1 2 3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 319
1 Kornfeld Eliyahu Peter 265
2 Maciej Los 249
3 BillWoodruff 205
4 Sergey Alexandrovich Kryukov 175
0 OriginalGriff 5,107
1 DamithSL 4,157
2 Maciej Los 3,595
3 Kornfeld Eliyahu Peter 3,450
4 Sergey Alexandrovich Kryukov 2,741


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 21 May 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100