# Hardfault when broadcast 2 differerent messages at once

**URL:** <https://forum.opencyphal.org/t/hardfault-when-broadcast-2-differerent-messages-at-once/545>\
**Category:** LibCyphal\
**Created:** [June 27, 2019, 12:28pm UTC](https://forum.opencyphal.org/t/hardfault-when-broadcast-2-differerent-messages-at-once/545 "2019-06-27T12:28:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![raserg](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/r/439d5e/32.png) [@raserg](https://forum.opencyphal.org/u/raserg)\
**Post date:** [June 27, 2019, 12:28pm UTC](https://forum.opencyphal.org/t/hardfault-when-broadcast-2-differerent-messages-at-once/545/1 "2019-06-27T12:28:23Z")

</div>

```auto
			uavcan::equipment::actuator::Status msg;
			msg.actuator_id = actuator_id;
			msg.position = actuator_status_data.position;
			msg.force = actuator_status_data.force;
			msg.speed = actuator_status_data.speed;
			msg.power_rating_pct = actuator_status_data.power_rating_pct;

			pub_status->broadcast(msg);
					
			uavcan::equipment::device::Temperature msg;
			msg.device_id = node_id;
			float temp = temperature_calculation(temperature_adc_value,THERMISTOR_B_COEFFICIENT,4095);
			msg.temperature = temp;
			pub_temperature->broadcast(msg);

```

If I leave only one message, then everything works fine.  
Period of shippment this messaes 50 ms.  
The probability of falling depends on the workload of the CAN bus.

Hardfault analysis always indicates:

```auto
Line 126 of "../../src/drivers/uavcan/libuavcan/./libuavcan/include/uavcan/util/linked_list.hpp"
   starts at address 0x803f4ba <uavcan::CanTxQueue::push(uavcan::CanFrame const&, uavcan::MonotonicTime, uavcan::CanTxQueue::Qos, unsigned short)+288>
   and ends at 0x803f4be <uavcan::CanTxQueue::push(uavcan::CanFrame const&, uavcan::MonotonicTime, uavcan::CanTxQueue::Qos, unsigned short)+292>.

```

linked\_list.hpp:126  
`if (root_ == UAVCAN_NULLPTR || predicate(root_))`

What can be wrong and how can you overcome this problem?

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [June 27, 2019, 1:29pm UTC](https://forum.opencyphal.org/t/hardfault-when-broadcast-2-differerent-messages-at-once/545/2 "2019-06-27T13:29:51Z")

</div>

Please increase your stack and see if the problem persists.

---

<div class="post-metadata">

**Author:** ![raserg](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/r/439d5e/32.png) [@raserg](https://forum.opencyphal.org/u/raserg)\
**Post date:** [June 27, 2019, 2:13pm UTC](https://forum.opencyphal.org/t/hardfault-when-broadcast-2-differerent-messages-at-once/545/3 "2019-06-27T14:13:59Z")

</div>

Yes, I have previously increased the Hpwork stack (in which this code is executed). Increased and uavcan process stack.  
Now I’ve increased it more, and now 8kb stacks, but the problem remains.

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [June 27, 2019, 2:15pm UTC](https://forum.opencyphal.org/t/hardfault-when-broadcast-2-differerent-messages-at-once/545/4 "2019-06-27T14:15:59Z")

</div>

> [@raserg](#):
>
> I have previously increased the Hpwork stack (in which this code is executed). Increased and uavcan process stack.

Your problem is caused by unsynchronized access to libuavcan from different threads. The library does not support this, please execute all your logic from one thread or use sub-nodes as described in the tutorial: [Open technology for real-time intravehicular distributed computing and communication based on modern networking standards](https://uavcan.org/Implementations/Libuavcan/Tutorials/12._Multithreading/)

---

<div class="post-metadata">

**Author:** ![raserg](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/r/439d5e/32.png) [@raserg](https://forum.opencyphal.org/u/raserg)\
**Post date:** [July 15, 2019, 12:28pm UTC](https://forum.opencyphal.org/t/hardfault-when-broadcast-2-differerent-messages-at-once/545/5 "2019-07-15T12:28:41Z")

</div>

Thanks! It seems the reason was exactly that.
