Calling dev_init() from the device constructor

Hi,

is it allowed to call dev_init() from the Tango device constructor.

We are getting the following segfault:

==== backtrace (tid: 9495) ====
0 libucs.so.0(ucs_handle_error+0x2fd)
1 libucs.so.0(+0x2fa3f)
2 libucs.so.0(+0x2fc0a)
3 libpthread.so.0(+0x14420)
4 libtango.so.10.1(Tango::AttrProperty::AttrProperty(…) +0x27)
5 libtango.so.10.1(std::vectorTango::AttrProperty::_M_realloc_append(…) +0xa4)
6 libtango.so.10.1(Tango::MultiClassAttribute::init_class_attribute(…) +0xba9)
7 libtango.so.10.1(Tango::DServer::init_device(…) +0x315)
8 libtango.so.10.1(Tango::DServerClass::device_factory(…) +0xb7)
9 libtango.so.10.1(Tango::DServerClass::DServerClass(…) +0x3b1)
10 libtango.so.10.1(Tango::DServerClass::init(…) +0x94)
11 libtango.so.10.1(Tango::Util::server_init(…) +0x3f)
12 lima2_tango(main+0xf4c)
13 libc.so.6(__libc_start_main+0xf3)
14 lima2_tango(+0x22c9e)

More info here: Resolve "Lima2: Adapt the Nexus Writer Virtual links" (!7326) · Merge requests · Bliss / bliss · GitLab

Any help on this will be appreciated.

Andy + Wout

As I just said to Wout, POGO is generating code which will invoke init_device() from the constructor.
So, yes, init_device() is supposed to be invoked from the constructor.

Can we have a stacktrace with debug symbols and line numbers?

The libucs library, if that is GitHub - openucx/ucx: Unified Communication X (mailing list - https://elist.ornl.gov/mailman/listinfo/ucx-group), is not something cppTango is using and that is at the top of the stacktrace on crashing.

Thanks Thomas and Reynald.

I did not provide more information since the question was just about the design pattern of a tango device constructor and init_device.

Reynald confirmed that the init_device usage in the constructor is a normal design pattern.

But perhaps init_device is doing things which cannot be done yet during construction?

tango/include/lima/tango/control.inl · develop · LimaGroup / Lima2 · GitLab
tango/include/lima/tango/receiver.inl · develop · LimaGroup / Lima2 · GitLab

We are digging into core dumps to understand the problem. If it is related to Tango I’ll ask more details questions with better traces.

Segfault on `init_device` (#339) · Issues · LimaGroup / Lima2 · GitLab

FYI libucs is on the top of the trace because we launch the servers with MPI

export TANGO_HOST=…
mpiexec -n 1 lima2_tango simulator_ctl : -n 1 lima2_tango simulator_rcv1 : -n 1 lima2_tango

tango/src/main.cpp · develop · LimaGroup / Lima2 · GitLab

So perhaps you are correct Thomas and the real error does not come from init_device but from MPI.

If one would strictly follow C++ principles then init_device must not be called from a constructor.

The reason simply being the fact that a C++ object does not exist until its constructor has finished successfully. From C++'s perspective init_device is a call on a C++ object and hence should not be called from the constructor.

That Pogo calls init_device can be justified if the functionality implemented in init_device is simple and does not require the object. Everything that is done in init_device that expects the object to exist will fail.

@tjuerges I agree with you. I think init_device() was created to intialise the device once the object existed and could assume it could use the Device object fully. Typical initialisation involved communication with hardware etc. I wonder why pogo then calls it from inside the constructor and if it has always been like this. It could be useful for the kernel experts to provide some guidelines on the correct use of dev_init().