?? test2.c
字號:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <strings.h>#include <time.h>#include <errno.h>#include <math.h>#include <signal.h>#include <sys/mman.h>#include <sys/stat.h>#include <sys/types.h>#include <semaphore.h>#include <pthread.h>#include "dbfunc.h"#define THREAD_QT 3typedef struct{ pthread_t thrd_id;} thrd_ctl_t;static thrd_ctl_t a_thrd_ctl[THREAD_QT+10];void ThrdFunc(int thrd_index);int main(){ int thrd_index; for(thrd_index=0; thrd_index<THREAD_QT; thrd_index++) { if(pthread_create(&a_thrd_ctl[thrd_index].thrd_id, NULL, (void *(*)(void *))ThrdFunc, (void *)thrd_index)) { printf("Thread create fail\n"); exit(1); } } for(thrd_index=0; thrd_index<THREAD_QT; thrd_index++) { pthread_join(a_thrd_ctl[thrd_index].thrd_id, NULL); } exit(0);}void ThrdFunc(int thrd_index){ int errcode, i; char buf[1024]; emp_t emp; resume_t resume; if(DbsConnect(thrd_index)) { printf("Thread %d connect fail\n", thrd_index); goto ERROR; } printf("Thread %d Connect OK\n", thrd_index); emp.no=thrd_index; if((errcode=DbsEMP_SEL(thrd_index, &emp))!=DB_OK) { printf("Thread %d select emp fail, errcode:%d\n", thrd_index, errcode); } else { printf("Thread %d select emp succeed\n", thrd_index); printf("no:%.0lf ", emp.no); printf("upd_ts:%s ", emp.upd_ts); printf("name:%s ", emp.name); printf("duty:%s ", emp.duty); printf("age:%d ", emp.age); printf("salary:%.2lf\n", emp.salary); } resume.no=thrd_index; resume.resume=(char *)malloc(32768); strcpy(buf, "我一個高中同學告訴我,他小時將“邊區的太陽紅又紅”聽成“變壓器的太陽紅又紅”!!!!!他還給我講了原因。因為他那時根本不知道“邊區”是什么?只是記得很清楚,每天傍晚時可以看見村子西邊紅紅的落日。最要命的是在他們村子西邊的某個高處架著一臺變壓器。傍晚的時候,剛好可以看到變壓器上方一輪紅日此美景讓我的同學印象頗深。于是便與每天傍晚都放的那首歌聯系起來。此君還納悶,為什么寫歌的人知道他們村的變壓器放在西邊。"); resume.resume[0]='\0'; for(i=0; i<1; i++) strcat(resume.resume, buf); if((errcode=DbsRESUME_INS(thrd_index, &resume))!=DB_OK) { printf("Thread %d resume insert fail, errcode:%d\n", thrd_index, errcode); DbsRollback(thrd_index); } else { printf("Thread %d Resume insert succeed\n", thrd_index); DbsCommit(thrd_index); } resume.no=thrd_index; resume.resume[0]='\0'; if((errcode=DbsRESUME_SEL(thrd_index, &resume))!=DB_OK) { printf("Thread %d resume select fail, errcode:%d\n", thrd_index, errcode); } else { printf("Thread %d resume select succeed\n", thrd_index); printf("no:%.0lf len:%d ", resume.no, strlen(resume.resume)); printf("resume:%s\n", resume.resume); } sprintf(buf, "delete from resume where no=%d", thrd_index); if(DbsSQLExec(thrd_index, buf)!=DB_OK) { printf("Thread %d delete resume fail\n", thrd_index); DbsRollback(thrd_index); } else { printf("Thread %d delete resume succeed\n", thrd_index); DbsCommit(thrd_index); } ERROR: DbsDisConnect(thrd_index); return;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -