From 37eafbff4fd33377fb7c4b3866e80570a33cfe8b Mon Sep 17 00:00:00 2001 From: chenxin <15505920258@163.com> Date: Fri, 19 Apr 2019 17:11:33 +0800 Subject: [PATCH 1/2] fix : fix optimization level to -O0 when in debug mode optimization level of g++ whill affect debug options of gdb. --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04399a5..0268fd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,11 @@ set(CMAKE_MACOSX_RPATH 0) set(LIBCO_VERSION 0.5) # Set cflags -set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -g -fno-strict-aliasing -O2 -Wall -export-dynamic -Wall -pipe -D_GNU_SOURCE -D_REENTRANT -fPIC -Wno-deprecated -m64) +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -g -fno-strict-aliasing -O0 -Wall -export-dynamic -Wall -pipe -D_GNU_SOURCE -D_REENTRANT -fPIC -Wno-deprecated -m64) +else() + set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -g -fno-strict-aliasing -O2 -Wall -export-dynamic -Wall -pipe -D_GNU_SOURCE -D_REENTRANT -fPIC -Wno-deprecated -m64) +endif() # Use c and asm enable_language(C ASM) From 6394774931eb73b30d37e14e5e14e4fc0770a367 Mon Sep 17 00:00:00 2001 From: chenxin <15505920258@163.com> Date: Fri, 19 Apr 2019 17:27:13 +0800 Subject: [PATCH 2/2] fix : add judge to avoid segment fault --- example_thread.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/example_thread.cpp b/example_thread.cpp index 4017710..5c7fafd 100644 --- a/example_thread.cpp +++ b/example_thread.cpp @@ -39,6 +39,10 @@ static void *routine_func( void * ) } int main(int argc,char *argv[]) { + if (arac != 2) { + printf("Usage:./example_thread x"); + return -1; + } int cnt = atoi( argv[1] ); pthread_t tid[ cnt ];