|
Why not have your main threads wait for your worker threads to finish (usually called a join) rather than sleeping and polling?
boost::thread has a join facility and if you're using something Microsofty you can get the same effect using WaitForMulipleObjects.
Cheers,
Ash
|
|
|
|
|
maked the test. it is the same as before. This is the result:
My notebook has 2 CPU so if I start a long function as a single thread the CPU go not more to 50%.
Using 3 parallel long threads the CPU goes to 100%.
But if the worker-thread are short it looks that the program spends more time in syncronization then in processing because the CPU stays under 45-40%.
I done the test also runung the program compiled in release mode (speed optimization) inside and outside Visual studio.... the result is the same.
does anybody has some tips?
Russell
|
|
|
|
|
How long are the threads processing for before they're terminating? If it's less than a second you're not going to get a big speedup. That's life unfortunately!
There are all sorts of things that can slow processing of threads down:
- the most common one is not partitioning the data properly so you've got complex synchronisation objects involved. It takes time to lock a mutex or raise a semaphore
- you're blowing the shared L2 cache. Either the data working set is too big to fit in the cache so all your threads slow down as they're punting each other's data out OR there's no locality of reference in the data structures you're using. For example sharing a map between threads can be eyewateringly slow compared to sharing a vector. You could try compiling for size and see if that affects the number of cache misses (faster code is usually bigger so less of it fits in the processor cache)
- it just takes time to start up a thread. Somewhere between 10ms and 100ms depending on your system
Anyway the upshot of this is it's a bit hard to work out what's wrong without seeing some code and then most of the people on here probably couldn't make very good guesses as to what's wrong (me included). The other moral of this story is to only start multiple threads when you've got something specific for them to do that's going to slow down the responsiveness of your application if you do it on your main thread.
Cheers,
Ash
|
|
|
|
|
Aescleal wrote: it just takes time to start up a thread. Somewhere between 10ms and 100ms depending on your system
oh ... too much ... that is surely the problem I verified with my routine!
I then need to restyle the main thread to find if it is useful or not fire up some worker-thread
thanks, Matteo
Russell
|
|
|
|
|
Russell' wrote: A simple solution I found is to start in the main-thread a loop that do a simple Sleep (for some ms) and then checks some flags that the worker-threads sets when ending. When it understand that all the threads are end it make some computations and start all again.
There are several MFC synchronization classes just for this.
Anytime you have to use Sleep() to get the desired result, it is most likely a bad design.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
i have wirtten a demo, which i want to chip the big file into the small ones by Memory-Mapped Files.
the main code:
HANDLE hFile = CreateFile(filePathName, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
pvFile = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, dwCurPart);
HANDLE hNewFile = CreateFile(fileName, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hNewFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwCurPart, NULL);
PVOID pvNewFile = MapViewOfFile(hNewFileMap, FILE_MAP_WRITE, 0, 0, 0);
memcpy(pvNewFile, pvFile, dwCurPart);
i can get the new files,but the file don't get any content.i think the "memcpy();" can let the content
copy into the new files. thanks for your help.
|
|
|
|
|
You have set the dwNumberOfBytesToMap parameter for the destination file to 0.
Memory mapped files cannot grow like a disk files.
You have to create the destination file with blanks and set the dwNumberOfBytesToMap to the desired number of bytes.
To create a blank file use SetEndOfFile after the CreateFile call.
|
|
|
|
|
Hi,
I have created an MSI setup using VS2008 Setup project. It is installing properly but at last screen which shows "Installation Complete" I have a checkbox "Launch Now". It launches exe. But anyhow it is not launching in Vista or Win7. It is launching in XP.
Any suggestion ??
Thanks,
Rahul Kulshreshtha
|
|
|
|
|
rahul.kulshreshtha wrote: It launches exe. But anyhow it is not launching in Vista or Win7. It is launching in XP.
any security issues?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
that is what I am also thinking. I think setup is running as normal process (it sometimes asks for "yes" or "no") but it is not able to run the exe.
|
|
|
|
|
Did you start the installation through the setup.exe that gets bundled with the installer or did you just click on the MSI? Vista and Windows 7 run programs called setup.exe with more privileges than msiexec* so that might be your problem.
Cheers,
Ash
*Not the whole story but near enough to generate a couple of WTF??s
|
|
|
|
|
I was running it through MSI, but just now I also tried with setup.exe but nothing worked. Does any one know how can my Finish page has a checkbox for Launch now. I think it is not available by default and I could not find it on Finish page inside "View->User Interface" but orca shows it but I don't know which commands it tries to fire to Launch Exe. If I found that place then I might have some clue to solve it.
|
|
|
|
|
|
Hi,
Can any body help me.
Why my ListCtrl is not displaying values for certain
columns.
I have 10 columns out of these only column 3 is not displaying the values.
I am using the SetItemText() api
Can any body help me.
|
|
|
|
|
Could you please post the relevant code?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
try{
while( !m_pFrame->m_DbMgr.m_Rs.IsEof() )
{
//--- LRU Index -----------
m_pFrame->m_DbMgr.m_Rs.GetFieldValue( "LruIndex", nLruIndex );
strTemp.Format( "%d", nLruIndex );
m_pFrame->m_nLruIndex = nLruIndex;
m_ListInfoCtrl.InsertItem( nLruIndex-1, strTemp );
//---- LRU Name ------------
m_pFrame->m_DbMgr.m_Rs.GetFieldValue( "LruName", strLruName );
m_ListInfoCtrl.SetItemText( nLruIndex-1, 1, strLruName );
//---- LRU Type -----------
m_pFrame->m_DbMgr.m_Rs.GetFieldValue( "LruType", nLruType );
strTemp = m_pFrame->m_strLruType[nLruType-7001];
m_ListInfoCtrl.SetItemText( nLruIndex-1, 2, strTemp );
//----- MIl Bus ----------------
m_pFrame->m_DbMgr.m_Rs.GetFieldValue( "MilBus", strTemp );
strTemp.Insert( 0, " " );
m_ListInfoCtrl.SetItemText( nLruIndex-1, 3, strTemp );
//---- RtNumber -----------
m_pFrame->m_DbMgr.m_Rs.GetFieldValue( "RTNumber", nRtNumber );
strTemp.Format( "%d", nRtNumber );
if ( nRtNumber>0 )
m_ListInfoCtrl.SetItemText( nLruIndex-1, 4, strTemp );
//---- No Of Arinc Ch -----------
m_pFrame->m_DbMgr.m_Rs.GetFieldValue( "NoOfArincCh", nNoOfArincCh );
strTemp.Format( "%d", nNoOfArincCh );
if ( nNoOfArincCh>0 )
m_ListInfoCtrl.SetItemText( nLruIndex-1, 5, strTemp );
//---- No Of Serial -----------
m_pFrame->m_DbMgr.m_Rs.GetFieldValue( "NoOfSerialPort", nNoOfSerialPort );
strTemp.Format( "%d", nNoOfSerialPort );
if ( nNoOfSerialPort>0 )
m_ListInfoCtrl.SetItemText( nLruIndex-1, 6, strTemp );
//---- No Of Discrete -----------
m_pFrame->m_DbMgr.m_Rs.GetFieldValue( "NoOfDiscreteCh", nNofDiscreteCh );
strTemp.Format( "%d", nNofDiscreteCh );
if ( nNofDiscreteCh )
m_ListInfoCtrl.SetItemText( nLruIndex-1, 7, strTemp );
//----- Description ----------------
m_pFrame->m_DbMgr.m_Rs.GetFieldValue( "Description", strDescription );
m_ListInfoCtrl.SetItemText( nLruIndex-1, 3, strDescription );
m_pFrame->m_DbMgr.m_Rs.MoveNext();
}
}catch( CADOException& e )
{
strSql = "CSIRBaseView::UpdateListControl():GetFieldValue "+e.GetErrorMessage();
MessageBox( strSql ); return FALSE;
}
|
|
|
|
|
Why don't you use the debugger to see the value of strTemp on execution of the offending lines:
m_pFrame->m_DbMgr.m_Rs.GetFieldValue( "MilBus", strTemp );
strTemp.Insert( 0, " " );
m_ListInfoCtrl.SetItemText( nLruIndex-1, 3, strTemp );
?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
It is coming yaar.
strTemp is showing the value " MilBus"
But it is not able to display the value only for that column.
Remaining columns it is showing the values
|
|
|
|
|
Hi,
are you there?
Please help me.
|
|
|
|
|
Yes, I'm here. I would try to simplify the debug approach, for instance try to pass a fixed string to such column.
You may also check the state of that column against the other ones.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
I tried by passing fixed string still it is not coming.
what to do?
Still I have I more big problem?
My List control displays about LRU names. It will be stored in access database
If we delete one LRU name in between 20 lru names ie 20 rows.
If i delete 10 th row. ie 10 th record in the database.
Again I will refresh the list control. at this time
nothing is displaying after 10 th record only first column ie LRU index it is displaying remaining columns it is showing any thing.
while reading from DB table the values are coming but list control is not displaying.
Please help me?
Otherwise our whole project will be stopped.
|
|
|
|
|
Hi Pallini?
are you there?
|
|
|
|
|
You already posted a question about this stuff, and I thought it was fixed?
|
|
|
|
|
no yaar
it was not fixed.
How to solve this problem.
|
|
|
|
|
Sakhalean wrote: no yaar
Hey, I thought 'Talk Like A Pirate Day' was in September!
|
|
|
|
|