C Programming: Debugging with pthreads

后端 未结 8 2025
余生分开走
余生分开走 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:44

    When I started doing multithreaded programming I... stopped using debuggers. For me the key point is good program decomposition and encapsulation.

    Monitors are the easiest way of error-free multithreaded programming. If you cannot avoid complex lock dependencies then it is easy to check if they are cyclic - wait until program hangs ans check the stacktraces using 'pstack'. You can break cyclic locks by introducing some new threads and asynchronous communication buffers.

    Use assertions, and make sure to write singlethreaded unittests for particular components of your software - you can then run them in debugger if you want.

提交回复
热议问题