第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

作業(yè)社區(qū)

探索學(xué)習(xí)新天地,共享知識(shí)資源!

0 提交作業(yè)
0個(gè) 布置作業(yè)
0 滿分作業(yè)
得分 100
學(xué)習(xí)任務(wù)

史啦啦 的學(xué)生作業(yè):

【圖片】 #include #include #include #include #include #include #include #define MAXEVENTS 10 #define FIFO_PATH "./fifo_epoll_ctl" int main(void) { int epfd,ret,fifo_fd; struct epoll_event ev; struct epoll_event ret_ev[MAXEVENTS]; char buffer[1024] = {0}; //創(chuàng)建有名管道 if(mkfifo(FIFO_PATH,0666) == -1 && errno != EEXIST) { perror("[ERROR] mkfifo(): "); exit(EXIT_FAILURE); } //以非阻塞模式打開管道 fifo_fd = open(FIFO_PATH,O_RDONLY | O_NONBLOCK); if(fifo_fd == -1) { perror("[ERROR] open(): "); exit(EXIT_FAILURE); } //創(chuàng)建epoll實(shí)例 epfd = epoll_create(1); if(epfd == -1) { perror("[ERROR] epoll_create(): "); close(fifo_fd); exit(EXIT_FAILURE); } //將管道文件描述符添加到epoll監(jiān)聽 ev.events = EPOLLIN |EPOLLHUP; //監(jiān)聽可讀和掛起事件 ev.data.fd = fifo_fd; if(epoll_ctl(epfd,EPOLL_CTL_ADD,fifo_fd,&ev) == -1) { perror("[ERROR] epoll_ctl(): "); close(fifo_fd); close(epfd); exit(EXIT_FAILURE); } printf("Listening FIFO: %s\n",FIFO_PATH); while(1) { ret = epoll_wait(epfd,ret_ev,MAXEVENTS,1000); //1秒超時(shí) if(ret == -1) { perror("[ERROR] epoll_wait(): "); break; } else if(ret == 0) { printf("Timeout.\n"); continue; } for(int i=0;i 0) { buffer[bytes_read] = '\0'; printf("Received: %s\n",buffer); } else if(bytes_read == -1 && errno != EAGAIN) { perror("[ERROR] read(): "); } } } } } close(fifo_fd); close(epfd); return 0; }

得分 100
學(xué)習(xí)任務(wù)

浪潮君 的學(xué)生作業(yè):

#include // 引入標(biāo)準(zhǔn)輸入輸出頭文件,用于 printf、fprintf 等函數(shù) #include // 引入標(biāo)準(zhǔn)庫頭文件,用于 atoi() 等函數(shù) #include // 引入網(wǎng)絡(luò)字節(jié)序轉(zhuǎn)換相關(guān)函數(shù)頭文件,如 inet_aton, htons, ntohs 等 int main(int argc, char *argv[]) { // 判斷命令行參數(shù)數(shù)量是否正確,應(yīng)為程序名 + IP + 端口,共 3 個(gè)參數(shù) if (argc != 3) { fprintf(stderr, "Usage: %s \n", argv[0]); // 使用說明 return 1; // 參數(shù)錯(cuò)誤,返回非0表示程序失敗 } // 1. IP 字符串轉(zhuǎn)為網(wǎng)絡(luò)字節(jié)序的 struct in_addr 結(jié)構(gòu)體 struct in_addr ip_addr; // 用于存儲(chǔ)網(wǎng)絡(luò)字節(jié)序格式的 IPv4 地址 if (!inet_aton(argv[1], &ip_addr)) { // 將字符串 IP 轉(zhuǎn)換為網(wǎng)絡(luò)字節(jié)序存入 ip_addr fprintf(stderr, "Invalid IP address\n"); // 轉(zhuǎn)換失敗,提示錯(cuò)誤 return 1; } // 2. 字符串端口轉(zhuǎn)數(shù)字(atoi)并轉(zhuǎn)換為網(wǎng)絡(luò)字節(jié)序(htons) uint16_t port_net = htons(atoi(argv[2])); // 字符串轉(zhuǎn)為整數(shù),然后轉(zhuǎn)換為大端格式 // 3. 輸出網(wǎng)絡(luò)字節(jié)序(原始格式,不適合人直接閱讀) printf("Network Byte Order:\n"); printf(" IP: 0x%x\n", ip_addr.s_addr); // IP 輸出為16進(jìn)制的大端整數(shù) printf(" Port: %u\n", port_net); // 端口以整數(shù)形式輸出(實(shí)際是大端格式) // 4. 轉(zhuǎn)回主機(jī)字節(jié)序并輸出可讀格式 printf("Host Byte Order:\n"); printf(" IP: %s\n", inet_ntoa(ip_addr)); // 將 IP 地址結(jié)構(gòu)體轉(zhuǎn)換為可讀的字符串 printf(" Port: %u\n", ntohs(port_net)); // 將端口號(hào)從網(wǎng)絡(luò)字節(jié)序還原為主機(jī)字節(jié)序 return 0; // 正常退出 }

得分 100
學(xué)習(xí)任務(wù)

Linkus 的學(xué)生作業(yè):

#include #include #include #include #include static int number = 0;//共享變量 static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; void *thread_handler(void *arg) { int cnt = atoi((char *)arg); int i,tmp; for(i = 0;i < cnt;i++){ pthread_mutex_lock(&mtx); printf("線程 [%ld] 生產(chǎn)一個(gè)產(chǎn)品,產(chǎn)品數(shù)量為:%d\n",pthread_self(),++number); pthread_mutex_unlock(&mtx); pthread_cond_signal(&cond); // 喚醒消費(fèi)者線程 } pthread_exit((void *)0); } int main(int argc,char *argv[]) { pthread_t tid; int i; int err; int total_of_produce = 0;//總的生產(chǎn)產(chǎn)品的數(shù)量 int total_of_consume = 0;//總的消費(fèi)產(chǎn)品的數(shù)量 bool done = false; for (i = 1;i < argc;i++){ total_of_produce += atoi(argv[i]); // 生產(chǎn)數(shù)量的總和 err = pthread_create(&tid,NULL,thread_handler,(void *)argv[i]); if (err != 0){ perror("[ERROR] pthread_create(): "); exit(EXIT_FAILURE); } } for (;;){ pthread_mutex_lock(&mtx); while(number == 0) // 當(dāng)產(chǎn)品數(shù)量為 0時(shí),讓線程阻塞,并釋放鎖,這里一般設(shè)置循環(huán),防止沒有重新獲取到鎖 pthread_cond_wait(&cond,&mtx); while(number > 0){ total_of_consume++; // 消費(fèi)產(chǎn)品總數(shù) printf("消費(fèi)一個(gè)產(chǎn)品,產(chǎn)品數(shù)量為:%d\n",--number); done = total_of_consume >= total_of_produce; // 判斷消費(fèi)者數(shù)量與產(chǎn)品數(shù)量 } pthread_mutex_unlock(&mtx); // 消費(fèi)者消費(fèi)完成之后,釋放鎖 if (done) break; }

微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)