📄 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 + -