C Programming: Debugging with pthreads

后端 未结 8 2035
余生分开走
余生分开走 2020-12-07 14:47

One of the hardest things for me to initially adjust to was my first intense experience programming with pthreads in C. I was used to knowing exactly what the next line of c

8条回答
  •  余生分开走
    2020-12-07 15:25

    In the 'thinking' phase, before you start coding, use the State Machine concept. It can make the design much clearer.

    printf's can help you understand the dynamics of your program. But they clutter up the source code, so use a macro DEBUG_OUT() and in its definition enable it with a boolean flag. Better still, set/clear this flag with a signal that you send via 'kill -USR1'. Send the output to a log file with a timestamp.

    also consider using assert(), and then analyze your core dumps using gdb and ffffd.

提交回复
热议问题