|
Just guessing here, but since these are UI Threads, what messages are being sent to them and what message will eventually cause the thread to exit?
Chris Meech
"what makes CP different is the people and sense of community, things people will only discover if they join up and join in." Christian Graus Nov 14, 2002.
"AAAAAAAAAHHHHHH!!!!! Those leaks are driving me crazy! How does one finds a memory leak in a garbage collected environment ??! Daniel Turini Nov. 2, 2002.
|
|
|
|
|
I don't send any messages to the thread. I create the thread, set the vars and resume it.. With in the thread I create a socket and try to make a connection to another pc running the same software. If I have an error connecting I PostQuitMessage(0); If it connects I send some info and receive some info, if I receive a bye message I close the socket and post a PostQuitMessage(0).. I log everything to a text file on both machines.. and the networking on both sides works perfect.. I can see everything that the thread is doing and I don't see any problems I can see every thread exit properly on both sides.
The only thing I can think of is that the thread is created and then it resumes but doesn't even go into the InitInstance().. Thats where the logging begins.. If it gets created and never runs InitInstance() I wouldn't see anything bad in the logs..
Rob
|
|
|
|
|
This probably won't fix the problem. OTOH it may make it go away. The general rule that I follow for implementing threads is based on the answer to the question, "Does the thread have to catch Windows messages?" The operative word is catch, not send, cause even a worker thread can send messages. If the answer to that question is yes, then I implement the thread as a UI thread. But if the answer is no, then I implement the thread as a worker thread. Based on the briefest of descriptions that you've supplied, I think your threading should be done within a worker thread. Did you consider this alternative and is there any reason for using a UI thread?
Chris Meech
"what makes CP different is the people and sense of community, things people will only discover if they join up and join in." Christian Graus Nov 14, 2002.
"AAAAAAAAAHHHHHH!!!!! Those leaks are driving me crazy! How does one finds a memory leak in a garbage collected environment ??! Daniel Turini Nov. 2, 2002.
|
|
|
|
|
Yeah, I have thought of using worker threads instead, the only problem is that my main application has a CAsyncSocket derived class that handles all of the network events.. and I needed to create another derived CAsyncSocket class for my thread.. That way the thread can send and receive on its own and so can the main application.. I also tried to get away from using CAsyncSocket and go straight WinSock.. but I saw the same results and CAsyncSocket is much easier to use.. o-well, I'm sure I will figure out this monster eventually..
Thanks for all the replys!
Rob
|
|
|
|
|
Hey Rob,
It appears as if one of two things are happening:
1. The threads are working fine, except they're not being destroyed. In other words, it only seems like every thread is being destroyed but for some reason, they're still running. Monitor your thread count. It should always be constant -- 0 or 3, right? If it keeps going up then they're not being destroyed.
2. Some threads are working fine and others aren't. This seems like an unlikely scenario, since it doesn't make much sense. Why would it not work consistenly if everything inside the threads is working fine, like you say? So... I don't know what to recommend. I'm just hoping it's something easy, like your PostQuitMessage not getting accross or the thread's not being closed, or something. You do create your threads with m_bAutoDelete set to TRUE, right?
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Hi Alvaro,
Good to hear from you again ... I just put the logging into the constructor and destructor of the thread.. and now I am really stumped.. It appears that every thread I create, start and close are doing exactly that the constructor gets logged and the destruction is logged too.. Yet after 10 minutes or so I see an extra thread associated with my process... WEIRD.. I am using the m_bAutoDelete set to TRUE..
Man I am really confused.. I created a int var called m_nThreadCount and set it to 0.. then each time I create a thread I ++ the count.. after 10 minutes or so I was up to 48 and I had 48 entry’s in the log all constructs had a matching destruct, yet I can see extra threads on my process....
What do you think?
|
|
|
|
|
RobJones wrote:
Yet after 10 minutes or so I see an extra thread associated with my process
How do you see it? Are you using the Task Manager for this? Is there any other section of code that could also be creating threads?
RobJones wrote:
after 10 minutes or so I was up to 48 and I had 48 entry’s in the log all constructs had a matching destruct, yet I can see extra threads on my process....
Again, how do you see these extra threads? And how many are we talking about?
This is all very weird stuff. Another approach you may wanna consider is to create a little test application that just creates 3 threads like you do and destroys them after 30 seconds. In other words, try the divide-and-conquer approach to see if you can isolate the problem. If you still see problems with that code, post it here and I'll test it myself to see if I can figure it out -- slow day today.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Alvaro Mendez wrote:
How do you see it? Are you using the Task Manager for this?
Yep, I'm using the Task Manager to look at the thread count..
Alvaro Mendez wrote:
Is there any other section of code that could also be creating threads?
Nope, I am creating the threads in just one function and that function gets fired by a Timer (Every 30 seconds). I can create a sample application that only does the threads and see what it does... If I still show the same results I'll be sure to post the results and source...
Thanks again!
Rob
|
|
|
|
|
Hello again,
I made a really basic test program and I was able to reproduce the problem.. I only see this problem on non development boxes.. machines with out VC++ installed on them.. and the problem may take a good half hour or so before you see it.. Do you have an email address that I can send you the source? I really appreciate all your help..
Thanks again,
Rob
|
|
|
|
|
I found the problem!
It has to do with your call to SetTimer inside the CMyThread's constructor. When CMyThread is created it's still within the context of the main thread. So the timer is created for the main thread and the WM_TIMER message is never received by the 3 child threads.
You know how I figured it out? I put this statement in the constructor:
TRACE("Starting thread: 0x%x\n", GetCurrentThreadId());
And I noticed that it didn't match the thread ID's in the "The thread 0xblah has exited with code 0" message". Then I commented out all the code that was manually calling OnClosing except the one in the PreTranslateMessage and viola! The threads started piling up.
So I'm sure you know the solution: move the SetTimer down to the InitInstance code. At that point, the thread is already alive and the timer will be created for it.
I'm happy to have helped. It sure was nice to get away from the Java code for a change.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Hello
Im developing a client/server solution and I want to send a database recordset from the server to the client? What is the best way to do it? (The server is using iocp, mfc and odbc)
|
|
|
|
|
How are the client and server communicating? If I were you, I would use HTTP[S] and XML. Just transform your recordset to XML.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Isnt it a quite large overhead for using xml? (in unmanaged c++)?
Transfering data (records) is not the only thing that my server does, so webservices isnt the thing for me. The server talks to a PABX (phone switch), monitors corporation extensions, communicates with the voicemail system etc etc. Transferring data is the smallest part =)
XML sounds nice, but the server will handle a lot of connections and will be in the same machine as 4 other server proccesses, so it cant to much cputime.
|
|
|
|
|
hi, i need to embed QuickTime movie on an ASP page (.mov file on server). i'm scanning thru QuickTime samples now.
can anyone point me to the right direction? i found some QuickTime samples here:
http://developer.apple.com/samplecode/Sample_Code/QuickTime/Basics/CocoaCreateMovie.htm
mainly for desktop apps. i dont know too much about ASP, but i have the feeling that "my code" dont have to stream anything in binary - there must be third party component that does this for u and I'm wondering if QuickTime does this for u with one of their API?
Thanks.
norm
|
|
|
|
|
I have a program running on a friend's Win98SE machine that fails to draw everything completely, however it draws everything fine on my machies Win98 and WinXP. After numerous attempts to isolate the problem, we stumbled onto a very strange occurance.
If the program is renamed, it will run consistently with some names but not other names. There is no pattern to the names and the code does not use the program name in any way.
The question for anyone, is there any possible explanation for this strange behavior. I am pulling out my hair to try and find an answer.
Pat
|
|
|
|
|
Pat O`Neil wrote:
If the program is renamed, it will run consistently with some names but not other names.
Change to a name that it runs on consistently and leave it. It sounds like there is some odd correlation to the name of the executable and some process you are trying to do, did you write the code?
Nick Parker
You see the Standards change. - Fellow co-worker
|
|
|
|
|
|
Pat O`Neil wrote:
Yes, I wrote the code.
I am assuming that you didn't include the name of the executable within the code itself?
Nick Parker
You see the Standards change. - Fellow co-worker
|
|
|
|
|
Hello,
I have an RTF file that I write to, as sort of a log file. In the main program, the user is allowed to choose a font that he wants the RTF to be written in. I notice that when wordpad saves a document with different fonts, the fonts appear in the font table like this
{\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\froman\fprq2\fcharset2 Wingdings 2;}
Mainly, I can understand all that except for the two middle portions of \f0 and \f1. \fswiss\fcharset0 and \froman\fprq2 are indistinguishable from the font name received from the Font Dialog that I use. How do I figure this out from within my program so that I may write the things that the RTF file needs to know?
|
|
|
|
|
AFAIK, \fswiss and \fcharset are used to help pick an appropriate font on systems where the exact font specified is not available. \fcharset uses one of the values defined in WINGDI.H (0 == ANSI_CHARSET), while [\fswiss|\froman|\fmodern|\fscript|\fdecor] equate to the [FF_SWISS|FF_ROMAN|FF_MODERN|FF_SCRIPT|FF_DECORATIVE] font family constants. You can obtain these from a LOGFONT structure if you have one, or probably just leave them out - if you have the font name, i *believe* it should work anyway.
---
|
|
|
|
|
You seem to be correct, about the leaving it out thing. It seems you have to put in \fcharsetN if N is not 0 that is. I was looking up the logfont thing right before I came to check back on this thread. Makes me wonder why they put in fswiss, froman, etc. if it's not really necessary. Here's a crazy one for ya... how bout fprq2? Hehe, I've seen that. By the way, if it comes down to me having to get the stuff out of the LOGFONT structure... how would i get the FF_SWISS/FF_ROMAN/ETC. out of the lfPitchAndFamily byte? I know it's bytes 4 - 7, but how would i localize those bits so that I would be able to label them by their macros? Thanks a lot for your help dude; I really appreciate it.
|
|
|
|
|
|
hi there,
i have a problem to pass a String (a very large one) from a Visual C++ Dll to a VB-Application.
The problem is that only the first 1024 letters reaching the VB-App - so where is rest? I am not very skilled in vb-programming so: is there a limited size of a string in VB?
What do you think is the problem?
Here is an example of the dll an vb - code:
//VC++ DLL -------------------------------------------------------------------
BSTR __stdcall RunDll2 (LPCSTR str )
{
CString s(str);
AfxMessageBox( s, MB_OK, 0);
//only for testing reasons:
CFile file;
CString strs;
if ( file.Open( "listerror.rtf", CFile::modeRead ) )
{
int size = file.GetLength();
char * cbuffer = new char[size-4];
file.Read(cbuffer, size);
strs = cbuffer;
file.Close();
}
s = strs;
//----------------------------------
LPSTR str1= new char[s.GetLength()];
strcpy(str1, s);
BSTR bstr = SysAllocString((OLECHAR*)str1);
return bstr;
}
-------------------------------------------------------------------
VB Code-------------------------------------------------------------------
Option Explicit
Private Declare Function myfunction Lib "DllTest.dll" Alias "RunDll2" (ByVal mystring As String) As String
Private Sub Main()
Dim mystring As String
Dim mystring2 As String
Dim out As String
mystring = "jkljökjklöjlksadfdasfdasf afkjsdölkfdf"
out = mystring
mystring2 = myfunction(mystring)
MsgBox mystring2
End Sub
|
|
|
|
|
You might want to try passing in a reference to a string instead of returning one from C++.
I had to populate a shared data structure (UDT) between VB and C, however, one of the members of the UDT was a String. I passed a reference to an array of UDT's to my C DLL, and used SysAllocString on the String member. The data passed fine. All in All i was returning about 40K of data in the one function call.
I dont have any useful code for you though.
Question: Are you using IDL?
Ryan Baillargeon
Software Specialist
Fuel Cell Technologies Inc.
|
|
|
|
|
Question for a C++ guru (Christian, etc.). What is the difference between the following types of enum declaration - I don't have a C++ language reference handy and they all seem to do the same thing:
enum EColour
{
red,
green,
blue,
};
typedef enum EColour
{
red,
green,
blue,
}
typedef enum EColour
{
red,
green,
blue,
} EColour
If I use any of the above, I can declare a variable of type colour, so why would I favour one over the other?
Not important, I'm just curious.
When I am king, you will be first against the wall.
|
|
|
|
|