Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined symbol: pthread_attr_setscope when using certain VTK libraries #247

Closed
swederik opened this issue Jun 26, 2019 · 6 comments
Closed

Comments

@swederik
Copy link

swederik commented Jun 26, 2019

Hello,

For Project Week 31 I am trying to build the PolySeg library for the web. PolySeg is used in Slicer to manage segmentations and convert between different representations (contour / ribbon / lablemap) of segmentation maps.

I've run into an issue which I believe is related to multithreading used by VTK (or perhaps ITK?). When I build I get this:

error: undefined symbol: pthread_attr_setscope

I'm posting to see if anyone has run into this issue or has any ideas on how to fix it.

Under the assumption that this is pthread in VTK, I'm trying to set CMAKE_USE_PTHREADS_INIT to False for VTK when building the dockcross image.

https://github.com/Kitware/VTK/blob/2345d908224ae8f2999f7a8783cefd32cd48f2cf/Common/Core/CMakeLists.txt#L328

I see that @thewtex has set some environment variable (ITK_GLOBAL_DEFAULT_THREADER) in the past that also deals with multithreading, so maybe this is related, or maybe there's a VTK equivalent?

https://github.com/InsightSoftwareConsortium/itk-js/pull/143/files#diff-389705e038e06cfe5a0459474146ee35R3

My in-progress PR is here: PerkLab/PolySeg#4

If I skip importing things from PolySeg and just use simple things like e.g. vtkSphereSource, everything builds and runs properly.

Quite possibly related:

https://github.com/Kitware/VTK/blob/6b559c65bb90614fb02eb6d1b9e3f0fca3fe4b0b/Common/Core/vtkConditionVariable.cxx#L25

Update: It looks like you can avoid the issue by adding -s ERROR_ON_UNDEFINED_SYMBOLS=0 to ITKBridgeJavaScript.cmake and rebuilding the docker image. I don't know yet if this actually impacts the functionality.

@thewtex
Copy link
Member

thewtex commented Jun 26, 2019

@swederik best wishes at Slicer Project Week -- awesome project!

To explain -- in ITK, we explicitly do not use pthreads and use an appropriate threading backend with Emscripten, so the pthread symbol issue is no longer present. VTK does not have this support, yet. However, Emscripten provides shims for library calls, including pthreads. We have not enabled Emscripten's experimental multithreading support (#213), and pthread calls do not have an effect. So, at some point in the future the vtkConditionVariable.cxx may need to be improved, but the pthread symbol warning can safely be ignored for now.

@swederik
Copy link
Author

swederik commented Jun 26, 2019

Ah nice, I was a bit worried about just ignoring a cryptic sounding error. When I ignore the error I can build and run things normally with some warnings. The only remaining issue I am having is that some VTK functions are not being found properly e.g. vtkImageStencil and vtkPolyDataToImageStencil. I have no clue why that is happening. At first I thought maybe it was the version of VTK that is in the dockcross image, but that looks fairly recent so I guess it's not an issue. I suppose it's something in my setup.

Update: Nevermind, I am dumb and had BUILD_SHARED_LIBS:BOOL=OFF on PolySeg because I blindly copied VTK's cmake call :-)

@EJShim
Copy link

EJShim commented May 8, 2020

@thewtex

If I try to run vtkSmartVolumeMapper Example using emscripten, I get error because it uses pthread_set_attr() in vtkImageShiftScale->Update()

Can it be resolved?

I tried to build VTK using -s USE_PTHREADS=1, but having runtime error saying : Blocking on the main thread is very dangerous, + crashes application

@thewtex
Copy link
Member

thewtex commented May 11, 2020

@EJShim itk.js 12.4.0 contains updates for VTK 9 and rendering support. However, volume rendering is not yet expected to work with VTK C++ compiled to wasm. VTK 9 focuses on TBB for multi-threading, most and use of pthread has been removed; it is better to avoid -s USE_PTHREADS.

@EJShim
Copy link

EJShim commented May 13, 2020

@thewtex Above example still cannot be compiled to wasm without volume rendering. I think pthread-using module is not removed yet for vtkImageShiftScale class. Will it be totally replaced in the future?

@thewtex
Copy link
Member

thewtex commented May 13, 2020

@EJShim it may be totally removed. To avoid the pthread call, try:

vtkThreadedImageAlgorithm::SetGlobalDefaultEnableSMP(true);

At the beginning of the program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants