如何在Waitforsingleobject()的线程和等效线程之间通信 我在学校刚开始C++,我试着同时做Linux和Windows。 这是我的代码和练习。问题是,我不知道如何重新运行线程,无论何时运行它,我都没有得到正确的字符 #include <iostream> #include <cstdlib> #include <pthread.h> using namespace std; bool t; #define NUM_THREADS 3 void *Saisie(void *PT) { char TT[150]; cout << "Entrez une chaîne de caractères :" <<endl; cin >> TT; t = true; pthread_exit(NULL); } void *Visualisation(void *PT) { cout<<"La chaine transmise est :" << &*(char*)PT <<endl; pthread_exit(NULL); } int main () { pthread_t TH1; pthread_t TH2; char TT[150]; t = false; while (t == false){ pthread_create(&TH1,NULL,Saisie,&TT); // Création du thread TH1 pthread_join(TH1,NULL); } if (t == true){ pthread_create(&TH2,NULL,Visualisation,&TT); // Création du thread TH2 pthread_join(TH2,NULL); } cout << "\nFin du programme – saisir une lettre pour fermer\n"; cin >> TT; } #包括 #包括 #包括 使用名称空间std; 布尔t; #定义NUM_线程3 void*Saisie(void*PT) { char-TT[150]; CUT同步线程并使用C++标准提供的库。这样,代码是可移植的。

如何在Waitforsingleobject()的线程和等效线程之间通信 我在学校刚开始C++,我试着同时做Linux和Windows。 这是我的代码和练习。问题是,我不知道如何重新运行线程,无论何时运行它,我都没有得到正确的字符 #include <iostream> #include <cstdlib> #include <pthread.h> using namespace std; bool t; #define NUM_THREADS 3 void *Saisie(void *PT) { char TT[150]; cout << "Entrez une chaîne de caractères :" <<endl; cin >> TT; t = true; pthread_exit(NULL); } void *Visualisation(void *PT) { cout<<"La chaine transmise est :" << &*(char*)PT <<endl; pthread_exit(NULL); } int main () { pthread_t TH1; pthread_t TH2; char TT[150]; t = false; while (t == false){ pthread_create(&TH1,NULL,Saisie,&TT); // Création du thread TH1 pthread_join(TH1,NULL); } if (t == true){ pthread_create(&TH2,NULL,Visualisation,&TT); // Création du thread TH2 pthread_join(TH2,NULL); } cout << "\nFin du programme – saisir une lettre pour fermer\n"; cin >> TT; } #包括 #包括 #包括 使用名称空间std; 布尔t; #定义NUM_线程3 void*Saisie(void*PT) { char-TT[150]; CUT同步线程并使用C++标准提供的库。这样,代码是可移植的。,c++,linux,multithreading,waitforsingleobject,C++,Linux,Multithreading,Waitforsingleobject,使用p螺纹库并不比上述选项更可取。对于Windows有一个pTrice实现,但是当您只能使用C++标准提供的一次写入时,为什么会遇到这样的麻烦。 要回答特定的查询,可以使用sleep原语,或者如果需要等待某个条件,则可以使用条件变量 看看你的问题是什么?第一个问题是为什么我的字符TT没有正确进入第二个线程。然后,如果用户在5秒后没有输入字符TT,程序需要不断要求用户输入新字符。请不要告诉我你的导师告诉你使用pthreadstd::threadhaS是标准C++的一部分,现在已经有超过6年的时间了

使用p螺纹库并不比上述选项更可取。对于Windows有一个pTrice实现,但是当您只能使用C++标准提供的一次写入时,为什么会遇到这样的麻烦。 要回答特定的查询,可以使用sleep原语,或者如果需要等待某个条件,则可以使用条件变量


看看你的问题是什么?第一个问题是为什么我的字符TT没有正确进入第二个线程。然后,如果用户在5秒后没有输入字符TT,程序需要不断要求用户输入新字符。请不要告诉我你的导师告诉你使用
pthread
std::thread
haS是标准C++的一部分,现在已经有超过6年的时间了。