|
1. Start 1st thread.
2. Wait for it to finish.
3. Start 2nd thread.
learningvisualc wrote: my problem is
??
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
In addition to the previous answer: is there a particular reason why you want to use a second thread ? You have to wait until the first thread is finished, so why don't you simply execute that task in the same thread as the first one. I don't really see an added value of starting a second thread when the first one terminates.
|
|
|
|
|
|
#include "stdafx.h"
#include "iostream"
using namespace std;
HANDLE hThread1 = NULL;
HANDLE hThread2 = NULL;
HANDLE hEvt1 = NULL;
DWORD __stdcall ThreadProc_1( LPVOID lpParameter )
{
for(int i = 0; i<10; i++)
{
cout<<"populating the list -- "<<i<<endl;
}
::SetEvent(hEvt1);
return 0;
}
DWORD __stdcall ThreadProc_2( LPVOID lpParameter )
{
while(::WaitForSingleObject(hEvt1, 5) == WAIT_TIMEOUT)
{
Sleep(5);
continue;
}
for(int i = 0; i<10; i++)
{
cout<<"doing operation on that list -- "<<i<<endl;
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
hEvt1 = CreateEvent(NULL, TRUE, FALSE, NULL);
hThread1 = CreateThread(NULL, 0, ThreadProc_1, NULL, 0, NULL);
hThread2 = CreateThread(NULL, 0, ThreadProc_2, NULL, 0, NULL);
while(::WaitForSingleObject(hThread2, 5) == WAIT_TIMEOUT)
{
Sleep(5);
continue;
}
if(hThread1)
::CloseHandle(hThread1);
if(hThread2)
::CloseHandle(hThread2);
if(hEvt1)
::CloseHandle(hEvt1);
return 0;
}
|
|
|
|
|
Xie Jinghui wrote:
while(::WaitForSingleObject(hEvt1, 5) == WAIT_TIMEOUT)
{
Sleep(5);
continue;
}
This has the same effect than:
::WaitForSingleObject(hEvt1, INFINITE);
but is more complex and less efficient as the OS every 5 seconds schedule the thread to be runt again; using a wait timeout of INFINITE is better because the OS suspend the thread and resume it only when the eventis signeled.
- You don't really need to create an event: the second thread could simply wait for the first thread to terminate
::WaitForSingleObject(hThread1, INFINITE);
|
|
|
|
|
Thank you,
I always overlook the details,,,
the program will be more efficient,
|
|
|
|
|
Make it single threaded - threads are only useful when doing parallel operatations, they're only overhead otherwise.
Cheers,
Ash
|
|
|
|
|
Hi
How to change the radio button caption text color( MFC ).By default it is showing Black color.I want the radio button caption text color, other than default color.
Thanks
|
|
|
|
|
|
In WM_CtlColor Handler write following Code.
HBRUSH CTestProjectDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd->GetDlgCtrlID() == IDC_RADIO1)//For IDC_RADIO1
pDC->SetTextColor(RGB(255,0,0));
return hbr;
}
|
|
|
|
|
Hi all,
I have made a .txt file in a format that it contains data per line i.e. in the format
/*text1*/
/*text2abc*/
And its not defined that how much data it can contain per line.
I am reading this file in a per line format basis using this code
CStdioFile ptr;
CString str;
int i = 0;
ptr.Open(file_name, CFile::ReadWrite, NULL);
while(ptr.ReadString(str))
{
m_List.InsertItem(i,str);
i++;
}
ptr.Close();
My problem is if a list contains more data(5000 lines or above) its taking a lot of time to read it.
I also know that i can read particular number of bytes from buffer but the problem is how can i know that the line has been completely read or not.
Can anybody please help me in this?
Is there any other way to read thid file.
Thanks in advance
|
|
|
|
|
I think your application is slow because of the huge number of items in the list control.
You may consider using a virtual list, see, for instance, the following CodeProject article: Using virtual lists.
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]
|
|
|
|
|
Read the file THEN populate the list. and as my colleague wrote, use a virtual list.
Watched code never compiles.
|
|
|
|
|
Hi,
I had written programs using TURBO C & C++ IDE. These were written for MS-DOS OS. When ever i talk about these programs i refer them as "16 bit programs (MS-DOS)". Is it right? cause MS-DOS is an os which could manipulate up to 16bits of information so a program written using its api should be 16bit programs besides DPMI(dos protected mode interface) or the TURBO C++ IDE.
I would like to have any kind of reply which could give more information about this and to conclude my doubt.
|
|
|
|
|
It depends on what you mean by MS-DOS, keep in mind since Windows XP MS-DOS is no longer part of the OS. I believe that is the first Windows version that ran a console rather then MS-DOS inside windows (or the other way around). And in Windows XP+ the console is a true 32bit application. In the 64bit version of Windows it depends on the program, but the default console is 64bit then.
A note on the 64bit Windows, I believe that if an application is 32bit it will start the WOW32 emulator.
|
|
|
|
|
Oh... So the virtual machine works like a 32 bit system isn't it?
What in Windows 98? I hope that virtual machine works as 16 bit.
I am using dosbox an emulator in windows xp because this xp 32bit version virtual machine does not render c graphics as expected.
I hope dosbox should run an emulator which is 16bit. Because i get all my outputs as expected. i have used EGAVGA.BGI Borland Graphics Library and i use lot of outport and inport function which interact with the keyboard and video card.
so can i still say that my programs are 16bit apps because they cannot access more memory than that unless we use memory managers which i have tried a lot but could not successfully use them. now we are far away form those concepts... i am documenting my old work . so is the reason for the flashback.
BESIDES I READ THIS AS FIRST REPLY AND I AM RESPONDING TO IT. I DID NOT READ THE OTHER REPLIES UNTILL I COMPLETED THIS REPLY. ANY WAY THANKS FOR ALL EXPERTS WHO HAD REPLIED TO ME.
http://vikku.info/ Today's Beautiful Moments are
Tomorrow's Beautiful Memories
modified on Saturday, October 30, 2010 4:39 AM
|
|
|
|
|
It depends which Turbo C++ you are using. If it is the ancient character-based one (looks like a DOS screen), then it generates 16-bit code. If, however, you use the more modern one (ca 2005, looks like a real Windows IDE), then it generates 32 bit code, even for console apps.
HTH
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
|
Yes you are right.
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
|
It's not a bad description to start with as all DOS programs start life as 16 bit programs. The calling convention for DOS was all real mode and register based so most parameters had to be 16 bit. If you wanted to pass 32 you had to use a structure or pack them in two registers.
However while all DOS programs start execution as 16 bit, by the early 90s most were starting to branch out a bit and would switch to either 16 or 32 bit protected mode fairly quickly, switching back to 16 bit real (or V86) mode when they needed to make system calls. it was a complete rat's nest and you're better off ignoring it unless you're interested in how the whole sorry mess evolved in the name of compatability.
Cheers,
Ash
|
|
|
|
|
oh. haha. hhmmm... nice. i am already out of that for the past 4 years. but still just a little love on it cause i have lived a lot with Turbo C++ and trying to mimic the same in windows like the interrupts for monitoring processes like file system.
thank you.
|
|
|
|
|
Hey, sorry if the threadtitle is a bit in-informative but I didn't know what to call it.
Ok now to my problem, I am playing around with arrays and stuff see here ->
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a[] = { "one", "two", "three" };
for (int i = 0;i <3;i++)
{
cout << a[i] << endl;
}
cin.get();
}
Now my problem is the "i < 3" let's say I wouldn't want to change that everytime i add another string to my array.
How would I do that?
Greetings!
|
|
|
|
|
there is a ARRAYSIZE macro you can use : ARRAYSIZE(a).
#define ARRAYSIZE(a) sizeof(a)/sizeof(a[0])
i don't recommend it. but it should work.
|
|
|
|
|