This forum has been archived. Please start a new discussion on GitHub.

[C++] crash using IceUtil::Timer


we are exploring the possibility to use Ice in our next software project.

However, we ran across several application crashes which we could boil down to a single line using IceUtil::Timer and it looks like this:
#include <IceUtil/Timer.h>

int main() {
    IceUtil::Timer timer;
    return 0;

When compiled on OS X 10.6.8 against Ice-3.4.2 (precompiled version) this program crashes with a segmentation fault.

The corresponding gdb backtrace looks like this:
#0  0x00007fff5fbff740 in ?? ()
#1  0x000000010078271e in startHook (arg=0x7fff5fbff6b0) at Thread.cpp:407
#2  0x00007fff802d7fd6 in _pthread_start ()
#3  0x00007fff802d7e89 in thread_start ()

We tried to run it on Linux but got a slightly different error (using Ice-3.4.1):
test: /Ice/include/IceUtil/Mutex.h:256: IceUtil::Mutex::~Mutex(): Assertion `rc == 0' failed.

I will check against Ice-3.4.2 tomorrow (I know about the support policy).

Any help or insight on this would be appreciated.

Best regards,



  • mes
    mes California
    Hi Manfred,

    Welcome to the forum.

    The IceUtil::Timer class is a reference-counted class, which is implied by its inheritance from IceUtil::Shared. As you have seen, bad things will happen if you attempt to allocate an instance of such a class on the stack.

    Here is how you should be allocating an instance:
    IceUtil::TimerPtr timer = new IceUtil::Timer;

    The TimerPtr type is a smart pointer for instances of Timer.

    Best regards,
  • Hello Mark,

    thanks for your fast response.

    Now that you mention the reference counting the solution seems obvious.
    Somehow we must have overlooked this problem.

    Best regards,