# Is running data streams of a multispectral camera in threads thread safe?

**URL:** <https://forum.commonvisionblox.com/t/is-running-data-streams-of-a-multispectral-camera-in-threads-thread-safe/1741>\
**Category:** Programming Questions\
**Tags:** cpp, acquisition, gigevision\
**Created:** [July 4, 2022, 3:58pm UTC](https://forum.commonvisionblox.com/t/is-running-data-streams-of-a-multispectral-camera-in-threads-thread-safe/1741 "2022-07-04T15:58:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![keerthitheja](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@keerthitheja](https://forum.commonvisionblox.com/u/keerthitheja)\
**Post date:** [July 4, 2022, 3:58pm UTC](https://forum.commonvisionblox.com/t/is-running-data-streams-of-a-multispectral-camera-in-threads-thread-safe/1741/1 "2022-07-04T15:58:21Z")

</div>

Dear Team,  
I am running my SW4000 line scan camera using multi threading. The camera gives out two streams DS0 (RGB) and DS1 (NIR). I am opening the device and getting the stream pointers and image stream using CVB++. Now, if I start the streams in two separate threads by the NIR stream always crashes for some reason. At lower resolutions, the streams give output as expected but at higher resolutions, once the RGB stream starts giving the output, the NIR stream crashes. So, it is allowed to run these streams separately in threads ? Are they thread safe ?

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [July 5, 2022, 5:34pm UTC](https://forum.commonvisionblox.com/t/is-running-data-streams-of-a-multispectral-camera-in-threads-thread-safe/1741/2 "2022-07-05T17:34:40Z")

</div>

Hi @keerthitheja,

yes different streams can be handled in different threads. Please check where the crash occurs. If happens inside one of our dlls or the CVB++ headers please contact support and send us a crashdump.

Cheers

Andreas

---

<div class="post-metadata">

**Author:** ![keerthitheja](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@keerthitheja](https://forum.commonvisionblox.com/u/keerthitheja)\
**Post date:** [July 8, 2022, 2:14pm UTC](https://forum.commonvisionblox.com/t/is-running-data-streams-of-a-multispectral-camera-in-threads-thread-safe/1741/3 "2022-07-08T14:14:48Z")

</div>

Hi @Andreas  
So, I tried to dump the crash using exception, the program mostly crashes at Stream-\>Wait(). The exception it gives me always is the **` composite is not an image`**. This exception mostly occurs only for the NIR stream.

Now that I am handling the exception, I am skipping that particular image and reading out the image acquired on the next trigger.

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [July 8, 2022, 2:34pm UTC](https://forum.commonvisionblox.com/t/is-running-data-streams-of-a-multispectral-camera-in-threads-thread-safe/1741/4 "2022-07-08T14:34:21Z")

</div>

Hi @keerthitheja

> [@keerthitheja](#):
>
> So, I tried to dump the crash using exception, the program mostly crashes at Stream-\>Wait(). The exception it gives me always is the **` composite is not an image`**. This exception mostly occurs only for the NIR stream.

Ok there is an exception thrown so this is not a crash but your responsibility to catch and handle it.  
By the way stating the message from exception helps a lot!

Anyway, the reason for the exception could still be an issue our side. We just recently fixed a bug that caused such an exception. Please update to the most recent CVB version. If there is still an exception please tell me the pixel format of the NIR stream.

Thanks

---

<div class="post-metadata">

**Author:** ![keerthitheja](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@keerthitheja](https://forum.commonvisionblox.com/u/keerthitheja)\
**Post date:** [July 11, 2022, 11:30am UTC](https://forum.commonvisionblox.com/t/is-running-data-streams-of-a-multispectral-camera-in-threads-thread-safe/1741/5 "2022-07-11T11:30:42Z")

</div>

Hi @Andreas  
So, I downloaded the latest release of 14.00.000 of CVB from the below link and installed it on my PC

[https://forum.commonvisionblox.com/t/common-vision-blox-for-windows/1574/34?u=keerthitheja](https://forum.commonvisionblox.com/t/common-vision-blox-for-windows/1574/34)

With this package, my code fails to compile. It throws an error while accessing the stream pointer using the line  
`device->Stream<Cvb::ImageStream>()`. The error it says is Stream expects an expression but got a type. But, if I look in the CVB++ documentation, the stream is defined to take types

[https://help.commonvisionblox.com/NextGen/14.0/cvbpp/d8/d60/class\_cvb\_1\_1\_device.html](https://help.commonvisionblox.com/NextGen/14.0/cvbpp/d8/d60/class_cvb_1_1_device.html)

Is the function Stream updated in the latest release ? or Am i missing something ? Please let me know how to go about this

Note: Now, I reverted back my CVB version to 13.04.006 and the code compiles fine.

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [July 11, 2022, 1:09pm UTC](https://forum.commonvisionblox.com/t/is-running-data-streams-of-a-multispectral-camera-in-threads-thread-safe/1741/6 "2022-07-11T13:09:35Z")

</div>

> [@keerthitheja](#):
>
> But, if I look in the CVB++ documentation, the stream is defined to take types

Yes, unfortunatelly we did not update the online reference yet. The local documentation is correct. We have moved `Stream<T>` to the `GenICamDevice` as it as the only device supporting it. In order to get a `GenICamDevice` use `auto device = Cvb::DeviceFactory::Open<Cvb::GenICamDevice>(...)`

Sorry for the inconvenience.

CVB 13.04.06 should also include the fix mentioned above.

---

<div class="post-metadata">

**Author:** ![keerthitheja](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@keerthitheja](https://forum.commonvisionblox.com/u/keerthitheja)\
**Post date:** [July 11, 2022, 1:31pm UTC](https://forum.commonvisionblox.com/t/is-running-data-streams-of-a-multispectral-camera-in-threads-thread-safe/1741/7 "2022-07-11T13:31:25Z")

</div>

Hi @Andreas  
Thank you for the reply. so the issue I had highlighted here below was seen with the version 13.04.006 of CVB.

> [@keerthitheja](#):
>
> So, I tried to dump the crash using exception, the program mostly crashes at Stream-\>Wait(). The exception it gives me always is the **` composite is not an image`**. This exception mostly occurs only for the NIR stream.

I am having difficulty in setting the pixel format for each stream individually using CVB++.

Setting the pixel format is via the CVB device nodemap and with this, I can either set it to RGB8 or Mono before I start the streams.

Is it possible to set the pixel format for each stream individually ?  
For more understanding of my problem, please refer to the below thread

[https://forum.commonvisionblox.com/t/modifying-individual-pixelformat-settings-for-dual-streams-of-a-multispectral-camera/1696?u=keerthitheja](https://forum.commonvisionblox.com/t/modifying-individual-pixelformat-settings-for-dual-streams-of-a-multispectral-camera/1696)

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [July 12, 2022, 12:51pm UTC](https://forum.commonvisionblox.com/t/is-running-data-streams-of-a-multispectral-camera-in-threads-thread-safe/1741/8 "2022-07-12T12:51:03Z")

</div>

> [@keerthitheja](#):
>
> I am having difficulty in setting the pixel format for each stream individually using CVB++.

You can set the pixel format of the streams in the device, respectively the device node map. This might be confusing as the streams also have node map but that is not the right one. If you want to change properties on the (remote) device streams you have to select the stream in the (remote) device node map first.

> **Some background information:**
>
> The GenTL architecture defines different modules each one can expose properties to the user via an XML that is interpreted by the GenAPI. The device is the only module that has two representaions, These modules include:
> 
> - _ **TL/System** _: refers to the binary the \*.cti file itself.
> - _ **Interface** _: The Grabber or NIC or USB HC
> - _ **TLDevice** _: The device as seen from inside the GenTL. Usually contains properties of the acquisition engine.
> - _**(Remote) Device**_: The physical device (camera). It may contains multiple streams but they do not get an extra interface.
> - _ **Stream** _ The streams as known by the GenTL, Only referring to acquisition engine properties.
> - _ **Buffer** _ Individual buffers for acquisition
