#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "tinyxml/tinyxml.h"
#include
#include
#include
#include
#define macxml "mac.xml"
using namespace std;
static bool usingmacxml = false;
pthread_mutex_t mutexmac = pthread_mutex_initializer;
struct mac_data{
string mac;
string account;
string password;
string status;
/// run cmd command
int runmsg(string cmd)
int rc = system(cmd.c_str());
if(!rc)
printf("excute %s, result is %d/n",cmd.c_str(), rc);
printf("cmd: %s, result is %d/n",cmd.c_str(), rc);
return rc;
///prepare environment:copy all ci content except case;run cienv_setup.sh to setup environment;"
void *prepareenv(void *threadarg)
struct mac_data *t;
t = (struct mac_data *) threadarg;
struct mac_data m;
m.mac = t->mac;
m.password = t->password;
m.account = t->account;
string mac = m.account+string("@") +m.mac;
string password = m.password;
string premsg = "./execute "+mac+" "+ password+" /"if [ -d ~/dd];then/nrm ~/dd -rf;/nfi;/"";
runmsg(premsg);
premsg ="./pscp "+password+" ~/dd "+mac+":~";
runmsg(premsg);
premsg ="./execute "+mac+" "+ password+" /"cd ~/dd/shell;sh ./ddenv_setup.sh;source ~/.bash_profile;/"";
runmsg(premsg);
/// 多執行緒配置環境
void setupenvinmultithread(vectormacs)
int tcount = macs.size();
pthread_t prethreads[tcount];
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,pthread_create_joinable);
int rc;
for (unsigned int i = 0;i < macs.size();i++)
struct mac_data m = macs[i];
cout<<"machine "system("sleep 3");
if(rc)
cout<<"pthread_create error code "void * status;
for(int j=0;jrc = pthread_join(prethreads[j],&status);
if(rc)
cout<<"pthread_join error code " 多執行緒的建立 include include include include include include include include struct number void create void arg int main int argc,char argv sleep 2 return ... 多執行緒程式指的是在同乙個程式中多個執行流併發執行,它們共享程序的同乙個位址空間,分別完成相應的任務,並通過共享位址空間等方式完成執行緒間通訊,cpu按照時間片輪轉等方式對執行緒進行切換和排程。通常而言,執行緒共享的程序資源包括 linux中線程的建立依賴於lpthread.so 庫,建立乙個thr... 執行緒建立函式 int pthread create pthread t restrict tidp 指向執行緒識別符號的指標 const pthread attr t restrict attr 設定執行緒屬性 void start rtn void 執行緒執行函式的起始位址 void restr...pthread多執行緒的建立
pthread 多執行緒
執行緒建立pthread