日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

c语言数据库线程池,C语言多线程中运行线程池,在线程池中运行线程池,,传递的结构体参数值为空/NULL/0...

發布時間:2025/3/15 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言数据库线程池,C语言多线程中运行线程池,在线程池中运行线程池,,传递的结构体参数值为空/NULL/0... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

typedef struct {

}LoanInfos;

typedef struct{

int cp;//主線程編號

int thread;//線程編號

long int time;

int arraysize;//二維數組的主數組有多少個元素

int arraykey;//二維數組的主數組的第幾個元素

}ListingInfos;

typedef struct{

int cp;//主線程編號

int thread;//線程編號

int thread_pool;//線程池編號

long int time;

int arraysize;//二維數組的主數組有多少個元素

int arraykey;//二維數組的主數組的第幾個元素

int arraykey_min;

}S_ListingInfos;

//配置單次請求處理標的數目為多少個

#define DEIL_LEN 10

//數據庫連接配置

char *db_host = "127.0.0.1";

char *db_user = "root";

char *db_pass = "password";

char *db_name = "database";

/*************以上為參數設置區域***************/

struct threadpool *user_pool;

struct threadpool *strategy_pool;

int main() {

curl_global_init(CURL_GLOBAL_ALL);

mysql_library_init(0, NULL, NULL);

user_pool = threadpool_init(100, 1000); //創建用戶組線程池,單次只處理15個線程,最多等待100個策略

s_pool = threadpool_init(100, 1000); //創建方法組線程池,單次只處理15個線程,最多等待100個策略

//創設線程

pthread_t t1, t2;

pthread_create(&t1, NULL, getlist, (void *)0);//傳遞線程參數代碼為0

usleep(100000 * 5);//間隔0.5毫秒創設線程

pthread_create(&t2, NULL, getlist, (void *)1);//傳遞線程參數代碼為1

pthread_join(t1, NULL);

//usleep(100000);//0.1秒

pthread_join(t2, NULL);

threadpool_destroy(s_pool);//銷毀線程池

threadpool_destroy(user_pool);//銷毀線程池

mysql_library_end();

return 0;

}

//刷新列表并處理詳情線程

void* getlist(void* m) {

int cp = (int)m;

pthread_detach(pthread_self()); //分離線程,使得它不能被其他線程回收或殺死的,它的存儲器資源在它終止時由系統自動釋放

//以下實現無線循環

for (int i;; i += 1) {

long int time;

long int r_time;

struct tm *gmt; ?//格林威治時間

struct tm *gmt2; ?//格林威治時間

struct timeval tv;

long int ss;

....//這里定義了很多局部變量

usleep(100000 * 20);//2秒刷新一次一次

//時間設置

{

gettimeofday(&tv, NULL);

ss = tv.tv_sec;

//time = ss * 1000 + tv.tv_usec / 1000;//獲取當前毫秒

//time -= refresh_time;//當前毫秒減去刷新毫秒,回到N毫秒之前

time = ss + 8 * 60 * 60;//當前時間戳

r_time = time - refresh_time / 1000;

gmt = gmtime(&r_time);//轉為格林威治時間

strftime(__request_time, BUFLEN, "%Y-%m-%d %H:%M:%S", gmt);

gmt2 = gmtime(&ss);//轉為格林威治時間

strftime(send_time, BUFLEN, "%Y-%m-%d %H:%M:%S", gmt2);

}

#####這里有一部分MySQL處理代碼和數據處理過程############

ListingInfos listing_infos_[l_size];

for (int _i = 0; _i < l_size; _i++)

{

listing_infos_[_i].thread = _i;

listing_infos_[_i].cp = cp;

listing_infos_[_i].time = time;

listing_infos_[_i].arraysize = l_size;

listing_infos_[_i].arraykey = _i;

//創建線程

int temp;

printf("【%d】【%d】創建線程前的ID號:%ld\n", cp, _i, listing_infos_[_i].Id);

threadpool_add_job(s_pool, ListThread, &listing_infos_[_i]);

}

}

}

void *ListThread(void *arg)

{

ListingInfos *listing_infos;

listing_infos = (ListingInfos *)arg;

printf("【%d】listid_thread【%d】線程中獲取的ID:%ld\n", listing_infos->cp, listing_infos->thread, listing_infos->Id);

//連接數據庫

MYSQL *conn;

MYSQL_RES *res;

MYSQL_ROW row;

//生成SQL

printf("【%d】listid_thread【%d】發送查詢策略SQL:%s\n", listing_infos->cp, listing_infos->thread, t_sql);

int arraysize = listing_infos->arraysize;

int arraykey = listing_infos->arraykey;

S_ListingInfos s_listing_infos[arraysize][100];

int count = 0;

while (row = mysql_fetch_row(res))

{

if (o >= 100) {

break;

}

unsigned long int *lengths = NULL;

lengths = mysql_fetch_lengths(res);

#######處理數據

//弄一個結構變量,存儲S組的信息

strategy_listing_infos[arraykey][o].arraysize = arraysize;

strategy_listing_infos[arraykey][o].arraykey = arraykey;

strategy_listing_infos[arraykey][o].arraykey_min = o;

.....//這里在整合數據

printf("\n【%d】【%d】【%d】標號%ld----策略:%s[%d]\t前\n", s_listing_infos[arraykey][o].cp, s_listing_infos[arraykey][o].thread, s_listing_infos[arraykey][o].thread_pool, s_listing_infos[arraykey][o].Id, s_listing_infos[arraykey][o].Name, s_listing_infos[arraykey][o].SId);

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的c语言数据库线程池,C语言多线程中运行线程池,在线程池中运行线程池,,传递的结构体参数值为空/NULL/0...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。