|
Hi All,
I have created 32 threads , out of these 20 threads are having infinite loop using while (1) {}. Remaining threads are also having infinite loop using while (1) {} but with some print statement. I have observed (With thirdparty utility) that threads WITHOUT print statement takes more time to context switch. Its almost few mins for me to get nothing on console because threads without printf were executed. After some time threads with printf statement executed in a shorter duration as my main () exited after a ::Sleep (300000). Why those threads without printf statement take much time to execute. Can any one have any idea...
Thanks
|
|
|
|
|
Although functionally a while(1){} loop could be described as doing nothing, the processor interprets it as a jump instruction. This effectively keeps the processor busy.
The printf statement relies on other resources (such as memory on your graphic card) which are slower, so when waiting for this, the processor isn't kept busy and can be assigned to some other thread by the OS.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
I concur with Thaddeus.
On a simple processor, a single such loop would raise CPU load to 100% and achieve nothing. On a more complex processor, it would take a few of them to get at or close to 100%, the net result would still be nihil.
Now why would you have a single busy loop like your empty while loop? And why would you have many of those? It makes little or no sense to me; it is like a company hiring personnel to sit at a desk and do nothing.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
pandit84 wrote:
Why those threads without printf statement take much time to execute.
I don't know what OS you are using but I will give you a Windows NT kernel answer. Its because the kernel scheduler is waiting for the threads to become eligible for a context switch. When the threads performing printf have completed I/O they become immediately eligible for a context switch. The threads in a busy loop consume more time because the process scheduler is waiting for what it considers *work* do be done. However since they are inside infinite do-nothing loop they will comsume an entire time slice.
What OS did you test this on? The process scheduler has evolved alot and on Microsoft Vista and above and I believe the threads performing I/O will recieve priority boost.
Best Wishes,
-David an eluDe
|
|
|
|
|
Hi,
I am trying to download a zip file from server using CInternetSession. But i am getting incorrect size from server.
My application is unicode and code as below:
pConnection = session.GetHttpConnection((LPCTSTR)strServerName, (INTERNET_PORT)nPort);
LPCTSTR pstrAcceptTypes = NULL;
LPCTSTR pstrVersion = NULL;
pHttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, &pstrAcceptTypes, pstrVersion, HttpRequestFlags);
pHttpFile->AddRequestHeaders(szHeaders);
pHttpFile->AddRequestHeaders(_T("User-Agent: GetWebFile/1.0\r\n"), HTTP_ADDREQ_FLAG_ADD_IF_NEW);
pHttpFile->SendRequest();
pHttpFile->QueryInfoStatusCode(dwRet);
int nFileLen = pFile->GetLength();
why I am getting incorrect size? Anything wrong in this code?
Same code was working with ANSI build and not working with unicode build.
modified on Thursday, January 13, 2011 5:43 AM
|
|
|
|
|
|
john5632 wrote:
int nFileLen = pFile->GetLength();
where is pFile defined and initialised? It does not appear in this code snippet.
I must get a clever new signature for 2011.
|
|
|
|
|
sorry this is
pHttpFile->GetLength();
|
|
|
|
|
Sorry, no idea, but maybe you should be looking at the information returned from your server.
[edit]Google found this[^], it may help.[/edit]
I must get a clever new signature for 2011.
|
|
|
|
|
Previously code was in ANSI and working fine but now I converted it to UNICODE and getting this issue.
Any problem with API to transdfr the string to server into UNOCODE format?
|
|
|
|
|
john5632 wrote: Any problem with API to transdfr the string to server into UNOCIDE format?
Assuming both ends are working in Unicode there should be no problems. You need to check both ends are following the same rules.
I must get a clever new signature for 2011.
|
|
|
|
|
Is the incorrect size comes in debug version? Please run in release mode and analyze nFileLen by means of messagebox or some thing else.
|
|
|
|
|
i wanted to create dynamically popupmenu on clicking rightclick... the item may very more than thousands worst case otherwise hundreds only. Is it possible?
|
|
|
|
|
yogish293 wrote: s it possible?
Did you try?
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]
|
|
|
|
|
For how long are you going to repost the same question ? You already got a lot of answers suggesting that it was a very bad design. Why don't you look at it from the user point of view and see if you can't use a more user-friendly approach ?
|
|
|
|
|
How much more information do you need on this? You have already been shown:
- This is not a good design, and you should consider alternatives.
- If you insist on doing it this way then you probably need to use a virtual menu - i.e. owner drawn.
I must get a clever new signature for 2011.
|
|
|
|
|
In that case instead of using regular menu , create a WS_POPUP style window, and handle the drawing and messages for performance improvement.
If u can Dream... U can do it
|
|
|
|
|
I guess you have to back to your class because its not a problem its very a basic question to write it,I think you dont know this secret(we have a site on the net its name is codeproject it has many articles(about menus and pop up menus,....)
Please dont read this post its a secret.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
|
Anything is possible; the question is: IS IT FEASABLE?
Why would you want to create menu with hundreds, not to mention thousand items. Put yourself in a position of a user of your application and imagine browsing hundreds of items to find one to choose.
You have to rethink your design.
JohnCz
MS C++ MVP
|
|
|
|
|
I am running my code in Winodws 7. I am using MessageBox() but it's not showing in the screen. The control is reaching there.
|
|
|
|
|
This is a very vague description.
You could try setting the hWnd parameter to HWND_DESKTOP.
Or Open Spy++ (aka SpyXX) from the Vistual Studio Tools Menu. Then find your application window in the Windows page. The message box should be a child window of the window you provide to the hWnd parameter
|
|
|
|
|
is it a windows service you are writing?
|
|
|
|
|
Whats the return value of MessageBox?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hi all,
I have 2 hard disk in my system. I want to get Logical drives of both hard drives i.e. Physical drive 1 contains c: and e: partitions and Physical drive 2 contains d: f: and g: partitions. I have used this code to get the hard disk details.... but it is giving wrong result....
TCHAR szTemp[BUFSIZE];
szTemp[0] = '\0';
if (GetLogicalDriveStrings(BUFSIZE-1, szTemp))
{
TCHAR szName[MAX_PATH];
TCHAR szDrive[MAX_PATH] = TEXT(" :");
BOOL bFound = FALSE;
TCHAR* p = szTemp;
do
{
*szDrive = *p;
if (QueryDosDevice(szDrive, szName, BUFSIZE))
{
CString str = szDrive;
str = str+szName;
m_Tree_Ctrl.InsertItem(str,root,TVI_LAST);
}
while (*p++);
} while (!bFound && *p);
}
m_Tree_Ctrl.Expand(root,TVE_EXPAND);
It is making a tree like
Drives
C:\Device\Harddiskvolume1
D:\Device\Harddiskvolume2
E:\Device\Harddiskvolume3
.
.
.
I am not getting what exactly is the problem...
Can anybody help me in this...
Thanks in advance
|
|
|
|