requires creative debugging. Consult with your local resident
guru debugger. Or hire external help.
int CCCP::LoadA2LDatabase(jcStr *fname){
/*
then call parser to parse the a2l file and load all the channel
values, if the parser returns with no error
return result of the load and parse.
zero is returned if no error in loading and parsing the a2l file
*/
int retval;
InitParser();//this will init the parser objects
char *temp;
//InitParser();
at this point the pointer fname is corrupted. it is pointing to
something else after InitParser
since i dynamically load the dlls that is i link the lib files, so
there is no explicit LoadLibrary function call from me.
i was not so sure that something is happening in the dlls
all these problems started once i made this parsing done by a separate
thread, so that i don't have to wait for my program to freeze for 10
minutes.
also when i call this function after a lot of setup(i.e., create many
other data structures related to the application and then call this
parser none of the above problem happens)
i can setup the program in such a way that i don't use the path, that
is giving me headache. but i would like to know why it is happening in
the first place. if there is anything
wrong in the code, i would like to correct it, before it creates a
bigger problem in future.
thanks
jc
how do you end a thread, which you started by CreateThread
how do you detect that you are leaking a thread.
i have a separate killthread function which looks like this
int CCCP::KillAThread(HANDLE *m_hHandle, bool &m_bBOOL){
int nRetry = 0;
if(m_bBOOL){
do{
m_bBOOL = FALSE;
if(WaitForSingleObject(*m_hHandle, 500) == WAIT_OBJECT_0){
//ExitThread(0);
CloseHandle(*m_hHandle);
*m_hHandle = NULL;
break;
}
nRetry++;
} while(nRetry < 3);
if(nRetry >= 3) return 1;
else return 0;
}
return 0;
}
i thought that this is working for me, as i never had any problem with
these threads. and at any time there will be atleast 4 to 5 live
processes in the application.
On Apr 30, 7:35 pm, "Alexander Nickolov" <agnicko...@mvps.org> wrote:
Omitting irrelevant groups.
Your thread routine prototype is wrong. Make it:
// header
static DWORD WINAPI ParseA2lThread(LPVOID)
// cpp
DWORD WINAPI CCCP::ParseA2lThread(LPVOID) {
// Don't call _endthread - that can crash since you didn't use
_beginthread[ex]
return 0;
}
I didn't see where you set up your m_strA2Lfname - I leave it up
to you to ensure it's set up correctly. Of course your class has to
outlive its thread as well, so you need to wait for your thread in
the class destructor or earlier. Note that closing a thread handle
does not stop the thread - you essentially leak running threads
in your code (not handles - the real threads). This most likely
has no detectable consequences, but may cause a crash if your class
is destroyed while its thread is still running. In an extreme case your
class is housed in a DLL and that DLL can be unloaded while your
thread is still running since its shut down completed sucessfully, but
it didn't stop its threads. This is a guaranteed crash and when it
happens and it's likely very hard to reproduce and diagnose.
With all of the above comments about gotchas, I still don't know
where does your crash happen. Can you give me an exact place
where your crash occurs? What does go wrong according to your
debugging experience?
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnicko...@mvps.org
MVP VC FAQ:http://vcfaq.mvps.org
=====================================
"jc" <k.jayachand...@gmail.com> wrote in message
news:1177965742.942024.256360@p77g2000hsh.googlegroups.com...
the corresponding code is
int CCCP::StartLoadA2lThread(void){
/*
function ccp thread
parameters: void
*/
//CParseWaitDialog *p_pwd;
DWORD dParseThreadID;
m_pWD = DisplayParseWaitDialog();
m_bA2lLoadThreadActive = TRUE;
if(m_hA2lLoadThread){
CloseHandle(m_hA2lLoadThread);
}
m_hA2lLoadThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
ParseA2lThread, this, 0,&dParseThreadID);
if(m_hA2lLoadThread){
sGmsg.StringCopy("parsing a2l file thread started");
m_pParent->SendMessage(CM_PRINT_MESSAGE2);
}
else{
sGmsg.StringCopy("a2l parse thread not started");
m_pParent->SendMessage(CM_PRINT_MESSAGE2);
}
return 1;
}
void CCCP::ParseA2lThread(LPVOID p){
/*
*/
CCCP *w = (CCCP *)p;
w->LoadA2LDatabase(w->m_strA2Lfname);
_endthread();
}
int CCCP::LoadA2LDatabase(jcStr *fname){
/*
then call parser to parse the a2l file and load all the channel
values, if the parser returns with no error
return result of the load and parse.
zero is returned if no error in loading and parsing the a2l file
*/
int retval;
InitParser();//this will init the parser objects
char *temp;
//InitParser();
//fname = m_strA2Lfname;
temp = fname->ReturnStr();
retval = Parser(temp, m_bA2lParseTalkative);
AnalyzeParseError(retval, fname, m_pWD);
DeleteParser();
InitTempLog();
m_pParent->PostMessage(CM_A2L_FILE_LOADED);
//AfterILoadA2lFile();
return retval;
}
thanks
jc
On Apr 30, 2:31 pm, "Alexander Nickolov" <agnicko...@mvps.org> wrote:
Make sure you are not passing pointers on your stack for your
thread to use. Always allocate on the heap data you are to send
to a different thread. Note this is just an educated guess as it's
hard to tell what your problem is with no code posted...
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnicko...@mvps.org
MVP VC FAQ:http://vcfaq.mvps.org
=====================================
"jc" <k.jayachand...@gmail.com> wrote in message
news:1177945430.435112.236610@n76g2000hsh.googlegroups.com...
On Apr 30, 9:32 am, dasjotre <dasjo...@googlemail.com> wrote:
On 30 Apr, 14:23, jc <k.jayachand...@gmail.com> wrote:
i'm developing a project using vc++.
the main exe is a win32 application. it needs two dlls. one is my
own
implementation of string operations. the other dll is to parse
a2l
files(it is similar to xml files, but it is based on asap2
standard).
i created the parser using bison and flex. then ported the code
to
vc+
+ environment including the files lex.yy.c(output from the flex
scanner) a2lgrammar.tab.cpp(output from bison) for post
processing
the
parser output and creating the data structure. the result is a
dll
file that i link with my application.
all was well till i realized that this post processing the parser
output(while the parser can finish parsing the file in less than
a
minute for a typical a2l file will be around 150,000 lines) takes
around 10 minutes, during the entire application freezes. so i
decided
to call the parsing using a separate thread.
i call the parser with the file name. before i call the parser
function i initialize the parser manually.
i reach the parser application in two different paths. in one
path
there is a conf file, which has the info about the a2l file and
from
there it calls the parser application. this goes well with no
problem.
but if i try to load the a2l file directly then the filename
pointer
gets corrupted. in different ways
sometimes when i enter the thread
sometimes when i initialize the dll
sometimes when i parse the file
but nothing happens when i call the a2l parse and process thread
after
i load the conf file.
i spent a week trying to figure this out and realized that this
is
beyond me.
any help and pointer will be appreciated
this is W32 not C++ problem
are you starting that thread inside DLLMain?
check
this:http://boost.org/doc/html/threads/implementation_notes.html#threads.i...
Hide quoted text -
- Show quoted text -
no i start the thread inside my application and call the dll
functions
from the thread.
i don't think i have anything like dllMain.
there are three functions that i use
0. start the thread (sometimes this file name pointer corrupts here)
1. initparser (this initialises the classes that parse, this is very
useful for me because, this will let me reparse a different file
without closing the application)(it corrupts here too)
2. parser(file name)(if it escaped before, now it is sure that it
gets
corrupted)
3. postprocess
4. copythe datastructure from the dll to the application(here i
duplicate all the strucutre, as it will be deleted soon, but these
data structure i need for the application)
4. deleteparser(delete all the memory that i allocated)
thanks
jc