我想通过控制哪些线程执行时调试多线程程序.我正在使用C++和gdb.除主线程之外我有两个线程(对于示例程序),我想调试一个线程,同时保持另一个线程停止.
这是我写的示例程序:
#include <iostream>
#include <pthread.h>
#include <stdlib.h>
#define NUM_THREADS 2
using namespace std;
void * run (void *) {
for (int i = 0; i < 3; ++i) {
sleep(1);
cout << i << " " << pthread_self() << endl;
}
pthread_exit(NULL);
}
int main (int argc, char** argv) {
cout << "Start..." << endl;
int rc;
pthread_t threads[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; ++i) {
rc = pthread_create(&threads[i], NULL, run, NULL);
if (rc) {
cout …Run Code Online (Sandbox Code Playgroud)