|
kuphryn wrote:
I have no experience using degugging tools such as Spy++, which a member mentioned at Anandtech, and the tool to monitor a specific thread in Visual C++.
Can you give me a quick walkthrough? I just need the order such as "1) select this 2) begin 3) look."
I'm afraid I don't have the time to teach you how to use the VC++ Debugger. Have a read of the Help, that should be enough to get started. There is also a good book by John Robbins called "Debugging Applications" MS Press and no doubt lots of stuff on the Web and in the MSJ Articles. John Robbins writes a regular column in MSJ/MSDN.
You absolutely have to know how to use the VC++ Debugger if you want to do any serious development work, especially if you are multithreading.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
|
Hi.
I believe I have figured out the problem. Here is a scenario. Let say you have a program with splitter window. There are two views and both are CEditView. Let say the top view calls a worker thread. While the worker thread is active, you focus the lower view and begin typing. What is the chance that the worker thread will never get deleted?
I just simulated the scenario above using a very simple program with a progress bar. If I focus on another window wile the progress bar is active, the program will not delete the progress bar, period.
I can upload the source code to that simple simulation anyone wants to see it.
Thanks,
Kuphryn
|
|
|
|
|
Kuphryn, I think that you should spend some time reading about multithreading. "Win32 Multithreaded Programming" by Cohen & Woodring is one book worth reading. Also study the articles on the Microsoft Web site.
I'm afraid you haven't got much of hope with multithreading until you have a very good understanding of all of the basic issues, and know how to use the VC++ Debugger.
I don't see what switching views has to do with whatever your worker thread is doing. If you want to post your sample code then by all means do so.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
I copied the code at "Re: using locale, numpunct, num_put to format number with ',' thsnds separator" to try. I also downloaded the Appedix-D Locale from Bjarne Stroustrup's site, and copied example at Section 4.2.1 Numeric Punctuation to try. None of both could compile!
The error message while compiling example found at Usenet:
error C2039: 'numpunct<char>' : is not a member of 'locale'
d:\program files\microsoft visual studio\vc98\include\xlocale(20) : see declaration of 'locale'
error C2664: '__thiscall std::locale::std::locale(const char *,int)' : cannot convert parameter 1 from 'class std::locale' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
And this is the error message while compiling Bjarne's example:
error C2664: '__thiscall std::locale::std::locale(const char *,int)' : cannot convert parameter 1 from 'class std::locale' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Maxwell Chen
|
|
|
|
|
I dunno what the state of iostreams is in the stuff that comes with VC, but I'd be inclined to install the STLPort, which now has an IOStreams implimentation included.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
What is STLPort? Can I program windows apps with this, as I do using VC++6 ? Where can I find it?
Maxwell Chen
|
|
|
|
|
1. A much better version of the STL
2. But of course, it's just another implimentation of parts of the std library. In fact they've even written it so there is a version that deals with VC's pathetic excuse for template support.
3. www.stlport.org, from memory
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Hi Maxwell, VC++ supports very defficiently this part of the standard library. The following modified version of the original sample compiles and works fine in VC++ 5.0 (hopefully it will work also for VC++ 6.0):
#include <iostream>
#include <locale>
#include <string>
using namespace std;
class my_punct:public std::numpunct<char>
{
protected:
char do_thousands_sep() const {return ',';}
std::string do_grouping() const {return "\3";}
public:
my_punct():numpunct<char>(){}
};
int main(){
locale loc = cout.getloc();
locale new_loc=_ADDFAC(loc,new my_punct);
cout.imbue(new_loc);
cout <<1000000 << endl;
cout.imbue(loc);
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you, Joaquin. It works in VC++6. But I could not find anything mentioning _AddFac() in MSDN2000...
And how should I do to cause printf(), sprintf(), CString::Format(), etc., change also ??
Maxwell Chen
|
|
|
|
|
Thank you, Joaquin. It works in VC++6. But I could not find anything mentioning _AddFac() in MSDN2000...
Look at the documentation for locale::locale (the ctor for locale .)
And how should I do to cause printf(), sprintf(), CString::Format(), etc., change also ??
Not sure. Try with setlocale .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
If in one thread the socket gets blocked in the WSAWaitForMultipleEvents() while in another thread
it cleans up the winsock library, what will happen?
|
|
|
|
|
If you call a WSACleanup() from a different thread, every socket in every other thread in the process gets closed. Or at least that's been my experience. Though mine was in a peculiar circumstance. So it might have been an exception rather than a rule.
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
And that means I will end the WSA block state and get an errorcode so that I can get out of that thread? Maybe not properly but still safely.
|
|
|
|
|
Thx ahead.
|
|
|
|
|
One thread is the main thread.Another is a socket transferring thread,in which I use the WSAWaitForMultipleEvents(...).I am afraid that maybe I can not use the PostThreadMessage(...) or
a semaphore to check the state because the thread may get blocked in the WSAWaitForMultipleEvents(...).
Is there any way to kill such a thread in the main thread?
|
|
|
|
|
And the TerminateThread() seems dangerous because I create a buf in the socket thread.
|
|
|
|
|
googoo wrote:
And the TerminateThread() seems dangerous because I create a buf in the socket thread.
If you want to kill a non-responding thread, there is little else you can do. I suggest you redesign the thread so that this sort of situation does not arise.
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
Not a non-responding thread,but an thread with a socket transferring loop:
create--listen--accept--read package--send package---
| |
-----------------------------------|
It seems difficult for me to avoid the WSAWaitForMultipleEvents()?
|
|
|
|
|
googoo wrote:
It seems difficult for me to avoid the WSAWaitForMultipleEvents()?
Then I think you should avoid using WSA_INFINITE as the time out interval. Use 5000 or something and then keep looping. Thus every 5 seconds you get a shot at closing the thread by posting a message to it.
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
No, I still have a problem.Because I am writing a DLL,and the DLL users will load and release it dynamically in shore intervals repeatly in their programs,it is hard for me to wait for 5 seconds every time.But a short timeout may cause other problems because of the busy lan.
Maybe any good suggestions on my thread design?
|
|
|
|
|
Use WaitForMultipleObjects instead. I replaced the following code (listing1) in a loop as you describe with the new code in listing 2 with no problems.
//listing 1:
while(1) {
if (WaitForSingleObject(pThis->m_hKillEvent, 100) == WAIT_OBJECT_0)
break;
if (!pThis->Connect())
{
Sleep(1000);
continue;
}
DWORD dwRet;
dwRet = WSAWaitForMultipleEvents(1,
&pThis->m_dataSocket.m_hEvent,
FALSE,
100,
FALSE);
if (dwRet == WSA_WAIT_TIMEOUT)
continue;
// respond to the network event
}
//Listing 2:
while(1) {
HANDLE hEvents[2] = {pThis->m_hKillEvent,pThis->m_dataSocket.m_hEvent};
DWORD dwRet;
dwRet = ::WaitForMultipleObjects(2,hEvents,FALSE,INFINITE);
if (dwRet == WAIT_OBJECT_0)
break;
if ( dwRet == WSA_WAIT_TIMEOUT ) {
continue;
}
// respond to the network event
}
|
|
|
|
|
My program need some functions of Explorer,then i wonder to know how can i
use the Explorer commands such as hotkeys,context menus and so on in my
Listview and Shell tree?
i am coming quietly just as i am leaving quietly.
|
|
|
|
|
First you need create a new class from CListCtrl,and then override the WM_CONTEXTMENU and other mouse message to handle your own functions.
Regards
http://www.ucancode.net/ (Xtreme Diagram++ MFC Extension library home page)
|
|
|
|