# VTK WebAssembly, vtkImageCanvasSource2D, and pthread\_attr\_setscope issue

**URL:** https://discourse.vtk.org/t/vtk-webassembly-vtkimagecanvassource2d-and-pthread-attr-setscope-issue/4280
**Category:** Web
**Created:** [September 22, 2020, 6:20pm UTC](https://discourse.vtk.org/t/vtk-webassembly-vtkimagecanvassource2d-and-pthread-attr-setscope-issue/4280 "2020-09-22T18:20:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Donny\_Zimmerman](https://discourse.vtk.org/user_avatar/discourse.vtk.org/donny_zimmerman/32/301_2.png) [@Donny\_Zimmerman](https://discourse.vtk.org/u/Donny_Zimmerman)
#### Post date: [September 22, 2020, 6:20pm UTC](https://discourse.vtk.org/t/vtk-webassembly-vtkimagecanvassource2d-and-pthread-attr-setscope-issue/4280/1 "2020-09-22T18:20:46Z")

</div>

I am trying to use vtkImageCanvasSource2D with WebAssembly and I am getting a runtime error “missing function: pthread\_attr\_setscope”. I think this is called when vtkImageCanvasSource2D updates. When I compile the project with Emscripten I always get the warning “warning: undefined symbol: pthread\_attr\_setscope”, but it wasn’t causing any issues until I started using the class vtkImageCanvasSource2D. I found this link: [https://github.com/InsightSoftwareConsortium/itk-js/issues/247](https://github.com/InsightSoftwareConsortium/itk-js/issues/247) and I added vtkThreadedImageAlgorithm::SetGlobalDefaultEnableSMP(true); at the beginning of my program and the runtime error disappears, but my image doesn’t get rendered. I can load a .vti file with vtkXMLImageDataReader and everything renders fine. I need to create my own vtkImageData at runtime with the vtkImageCanvasSource2D functionality. I can run the same program with VTK C++ on my Windows machine and the image renders fine. Seems to be a problem with that class, WebAssembly, and pthreads. Any help is appreciated.

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [September 22, 2020, 6:36pm UTC](https://discourse.vtk.org/t/vtk-webassembly-vtkimagecanvassource2d-and-pthread-attr-setscope-issue/4280/2 "2020-09-22T18:36:39Z")

</div>

I think WebAssembly does not support pthread hence the issue. But there might be some option now (compilation flag or else) to handle that (but don’t know). Searching online might allow you to find a possible path forward.

---

<div class="post-metadata">

### Author: ![Donny\_Zimmerman](https://discourse.vtk.org/user_avatar/discourse.vtk.org/donny_zimmerman/32/301_2.png) [@Donny\_Zimmerman](https://discourse.vtk.org/u/Donny_Zimmerman)
#### Post date: [September 22, 2020, 6:51pm UTC](https://discourse.vtk.org/t/vtk-webassembly-vtkimagecanvassource2d-and-pthread-attr-setscope-issue/4280/3 "2020-09-22T18:51:37Z")

</div>

Thanks Sebastien. I was thinking of recompiling VTK for wasm without pthread support, but I am unable to find a cmake definition to disable pthreads it in VTK. Does anybody know how to disable pthreads when compiling VTK? Here is the configuration I used to compile VTK for wasm:

cmake   
-G Ninja   
-DCMAKE\_TOOLCHAIN\_FILE=${CMAKE\_TOOLCHAIN\_FILE}   
-DBUILD\_SHARED\_LIBS:BOOL=OFF   
-DCMAKE\_BUILD\_TYPE:STRING=Release   
-DVTK\_ENABLE\_LOGGING:BOOL=OFF   
-DVTK\_ENABLE\_WRAPPING:BOOL=OFF   
-DVTK\_LEGACY\_REMOVE:BOOL=ON   
-DVTK\_OPENGL\_USE\_GLES:BOOL=ON   
-DVTK\_USE\_SDL2:BOOL=ON   
-DVTK\_NO\_PLATFORM\_SOCKETS:BOOL=ON   
-DVTK\_MODULE\_ENABLE\_VTK\_hdf5:STRING=NO   
/work/src

---

<div class="post-metadata">

### Author: ![Donny\_Zimmerman](https://discourse.vtk.org/user_avatar/discourse.vtk.org/donny_zimmerman/32/301_2.png) [@Donny\_Zimmerman](https://discourse.vtk.org/u/Donny_Zimmerman)
#### Post date: [September 24, 2020, 3:37am UTC](https://discourse.vtk.org/t/vtk-webassembly-vtkimagecanvassource2d-and-pthread-attr-setscope-issue/4280/4 "2020-09-24T03:37:25Z")

</div>

I found the problem. I am reading a binary file that contains the data I am creating the vtkImageData with. When running on Windows and I need to create a short from two bytes this works fine:

> ((char)(a)) | (((short)((char)(b)))\<\<8))

It does not work the same when compiled with Emscripten. I changed to:

> (((short)a) \<\< 8) | (0x00ff & b)

and it works on both platforms.

I still have to add:

> vtkThreadedImageAlgorithm::SetGlobalDefaultEnableSMP(true);

at the beginning of my program to get rid of the “missing function: pthread\_attr\_setscope” runtime error.
