Problem with MSVCRTD.dll

Hi,
I have a multithreaded COM inproc server which uses C runtime library function fprintf, gettime and fflush to log the messages from all the threads in one file.

The problem is that my application gives exception while executing one of the above function. if i comment the fprintf and fflush it gives error in gettime. But if fprintf and fflush are not commented error always comes in fprintf.

I couldnt track the problem because the frequency of the exception is not regular sometimes it comes after an hour or sometimes after running 3/4 hrs.

I dont know whether,

I am using the library in incorrect way,

or whether i am currpting any memory (because when i debug the exception it shows that the thread block data ptr is either corrupted or it contains garbage)

or the problem is with the library.

if anyone here could guide me.

thanx,
Manish

Get your FREE Email and Voicemail at Lycos Communications at
http://comm.lycos.com

This seems like a simplistic question, but do you have a mutex or critical
section guarding your accesses to fprintf, fflush, and gettime? Do don’t
want multiple threads stomping on your file data structures.

Terry

“Manish Sapariya”

> cc:
Sent by: Subject: [ntdev] Problem with MSVCRTD.dll
xxxxx@lis
ts.osr.com

09/21/00 11:46 PM
Please respond to
“NT Developers
Interest List”

Hi,
I have a multithreaded COM inproc server which uses C runtime library
function fprintf, gettime and fflush to log the messages from all the
threads in one file.

The problem is that my application gives exception while executing one of
the above function. if i comment the fprintf and fflush it gives error in
gettime. But if fprintf and fflush are not commented error always comes in
fprintf.

I couldnt track the problem because the frequency of the exception is not
regular sometimes it comes after an hour or sometimes after running 3/4
hrs.

I dont know whether,

I am using the library in incorrect way,

or whether i am currpting any memory (because when i debug the exception it
shows that the thread block data ptr is either corrupted or it contains
garbage)

or the problem is with the library.

if anyone here could guide me.

thanx,
Manish

Get your FREE Email and Voicemail at Lycos Communications at
http://comm.lycos.com


You are currently subscribed to ntdev as: xxxxx@cirilium.com
To unsubscribe send a blank email to $subst(‘Email.Unsub’)

Hi,
I am using Multithreaded debug library, so the library itself is serilizing the access to my file.

Manish

On Fri, 22 Sep 2000 05:26:05
Terry_Gin wrote:

This seems like a simplistic question, but do you have a mutex or critical
section guarding your accesses to fprintf, fflush, and gettime? Do don’t
want multiple threads stomping on your file data structures.

Terry

“Manish Sapariya”

> > cc:
> Sent by: Subject: [ntdev] Problem with MSVCRTD.dll
> xxxxx@lis
> ts.osr.com
>
>
> 09/21/00 11:46 PM
> Please respond to
> “NT Developers
> Interest List”
>
>
>
>
>
>Hi,
>I have a multithreaded COM inproc server which uses C runtime library
>function fprintf, gettime and fflush to log the messages from all the
>threads in one file.
>
>The problem is that my application gives exception while executing one of
>the above function. if i comment the fprintf and fflush it gives error in
>gettime. But if fprintf and fflush are not commented error always comes in
>fprintf.
>
>I couldnt track the problem because the frequency of the exception is not
>regular sometimes it comes after an hour or sometimes after running 3/4
>hrs.
>
>I dont know whether,
>
>I am using the library in incorrect way,
>
>or whether i am currpting any memory (because when i debug the exception it
>shows that the thread block data ptr is either corrupted or it contains
>garbage)
>
>or the problem is with the library.
>
>if anyone here could guide me.
>
>thanx,
>Manish
>
>
>Get your FREE Email and Voicemail at Lycos Communications at
>http://comm.lycos.com
>
>—
>You are currently subscribed to ntdev as: xxxxx@cirilium.com
>To unsubscribe send a blank email to $subst(‘Email.Unsub’)
>
>
>
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@lycos.com
>To unsubscribe send a blank email to $subst(‘Email.Unsub’)
>
>

Get your FREE Email and Voicemail at Lycos Communications at
http://comm.lycos.com

> I am using the library in incorrect way,

Looks like so.
Do you remember that if the thread wants to use the CRT functions which use
the per-thread space, it must be created by _beginthreadex and not with the
simple CreateThread?
In case of inproc COM server, the threads are created by the calling EXE
(which can be mtx.exe - Microsoft Transaction Server, which is in fact a
part of the COM framework used to export the DLL classes to the network
among all other things) or by the COM library (depends on the COM threading
model).
There is no guarantee at all that your DLL is called by the thread started
with _beginthreadex. So - do not use CRT in COM inproc servers.
A good way of logging is to create a writable memory-mapped file and just
memcpy or FormatString to the mapping. This is how IIS’s logging works.
In this case, even if your process will crash - MM will guarantee that all
these pages will be flushed to the log file.

Max

Hi,
thanx now everything works fine.

But if i use memory mapped file, what about serialization. I will have to serialize all the threads which are logging through my dll, isnt it.

and another reason i am using crt is the time functions, i.e. the functions which gives me time in sturct as well as string format.

could you suggest me something else for this functions also.

regards,
Manish

On Mon, 25 Sep 2000 01:15:53
Maxim S. Shatskih wrote:

> I am using the library in incorrect way,

Looks like so.
Do you remember that if the thread wants to use the CRT functions which use
the per-thread space, it must be created by _beginthreadex and not with the
simple CreateThread?
In case of inproc COM server, the threads are created by the calling EXE
(which can be mtx.exe - Microsoft Transaction Server, which is in fact a
part of the COM framework used to export the DLL classes to the network
among all other things) or by the COM library (depends on the COM threading
model).
There is no guarantee at all that your DLL is called by the thread started
with _beginthreadex. So - do not use CRT in COM inproc servers.
A good way of logging is to create a writable memory-mapped file and just
memcpy or FormatString to the mapping. This is how IIS’s logging works.
In this case, even if your process will crash - MM will guarantee that all
these pages will be flushed to the log file.

Max


You are currently subscribed to ntdev as: xxxxx@lycos.com
To unsubscribe send a blank email to $subst(‘Email.Unsub’)

Get your FREE Email and Voicemail at Lycos Communications at
http://comm.lycos.com