2007/4/26, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:

ymoona wrote:
> Thank for you patches, they seem to work fine here.
> I'm also trying to find and fix some leaks.
>
> I have a problem with OsTimerTask.cpp line 36.
> OsBSem* OsTimerTask::sLock = new OsBSem(OsBSem::Q_PRIORITY,
OsBSem::FULL);
>
> there is created an OsBSem object ( actually it is created twice ) but
> it is
> never deleted. Because this is a dynamic initializer it is called even
> before the main(). I'm not sure who owns the
> semaphore and who should delete it. I'm unable to delete it  from the
> main() because sLock is private. Does every timertask has its own
> semaphore or is there just one globally?
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> sipxtapi-dev mailing list
> [email protected]
> List Archive: http://list.sipfoundry.org/archive/sipxtapi-dev/

Read http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.16
regarding static initialization fiasco in C++.

That is why there are dynamic sigletons in the whole code. Some of them
can be made static, but not all.

This lock is used to make sure only 1 instance of OsTimerTask can be
created in multithreaded environment. If you delete it, it will be
impossible to restart sipxtapi. OsTimerTask::destroyTimerTask is not
called from any destructors of static members, so the lock could be made
static without breaking anything.

Try making OsTimerTask static singleton too. That could however be
potentially dangerous because we post a message to the message queue and
some static members of other classes could be required that at that time
are already uninitialized.

Jaroslav Libak

_______________________________________________
sipxtapi-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipxtapi-dev/


I tried making it static, but then I get an access violation when I try to
acquire a lock.
I made it static like this: OsBSem* OsTimerTask::sLock;

But then the constructor is not called causing an access violation

when I put a break point print on the original
initialisation, I see that it is called twice.
Function: `dynamic initializer for 'OsTimerTask::sLock''(void), Thread:
0xA80 OsFileBase::touch, Caller _initterm, Address 0x101F7740
Function: `dynamic initializer for 'OsTimerTask::sLock''(void), Thread:
0xA80 OsFileBase::touch, Caller _initterm, Address 0x00449580

How do I make sLock static?
_______________________________________________
sipxtapi-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipxtapi-dev/

Reply via email to