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

Cmake release segmentation fault #3

Closed
GaaiLam opened this issue Mar 9, 2021 · 1 comment
Closed

Cmake release segmentation fault #3

GaaiLam opened this issue Mar 9, 2021 · 1 comment

Comments

@GaaiLam
Copy link

GaaiLam commented Mar 9, 2021

When I build the codes with cmake (build type release), a segmentation fault occured, which will disappear when the "release" flag is removed. I tried to locate the codes where the segmentation fault occured but failed. Here is the only modification of the codes:

void KD_TREE::stop_thread(){

    pthread_mutex_lock(&termination_flag_mutex_lock);
    termination_flag = true;
    pthread_mutex_unlock(&termination_flag_mutex_lock);
    printf("0\n");
    if (rebuild_thread) pthread_join(rebuild_thread, NULL);
    printf("1\n");
    pthread_mutex_destroy(&termination_flag_mutex_lock);
    pthread_mutex_destroy(&rebuild_logger_mutex_lock);
    pthread_mutex_destroy(&rebuild_ptr_mutex_lock);
    pthread_mutex_destroy(&points_deleted_rebuild_mutex_lock);
    pthread_mutex_destroy(&working_flag_mutex);
    pthread_mutex_destroy(&search_flag_mutex);     
}

And my CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.2)
project(ikdtree)

add_compile_options(-std=c++17)
set(CMAKE_BUILD_TYPE "Release") // if I remove this line, the segmentation fault will disappear

include_directories(
  include
)

add_executable(ikdtree_demo
  src/ikd_Tree_demo.cpp
  src/ikd_Tree.cpp
)
target_link_libraries(ikdtree_demo pthread)

The output is as follows:

Multi thread started 
0
Rebuild thread terminated normally
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
[1]    150531 segmentation fault (core dumped)

It seems that the segmentation fault occured in pthread_join(), which makes me confused. Could you please help me to solve the problem?

@GaaiLam
Copy link
Author

GaaiLam commented Mar 9, 2021

After following #2 ,the segmentation fault fixed! Thank you!

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

1 participant