- for (int i = 0; i < ms_setting.nthreads; i++) {
- ms_thread_ctx[i].thd_idx = i;
- ms_thread_ctx[i].nconns = ms_setting.nconns / ms_setting.nthreads;
-
- /**
- * If only one server, all the connections in all threads
- * connects the same server. For support multi-servers, simple
- * distribute thread to server.
- */
- ms_thread_ctx[i].srv_idx = i % ms_setting.srv_cnt;
- ms_thread_ctx[i].tps_perconn = ms_setting.expected_tps / ms_setting.nconns;
- ms_thread_ctx[i].exec_num_perconn = ms_setting.exec_num / ms_setting.nconns;
- }
+ /**
+ * If only one server, all the connections in all threads
+ * connects the same server. For support multi-servers, simple
+ * distribute thread to server.
+ */
+ ms_thread_ctx[i].srv_idx= i % ms_setting.srv_cnt;
+ ms_thread_ctx[i].tps_perconn= ms_setting.expected_tps
+ / (int)ms_setting.nconns;
+ ms_thread_ctx[i].exec_num_perconn= ms_setting.exec_num
+ / ms_setting.nconns;
+ }
+
+ if (pthread_key_create(&ms_thread_key, NULL))
+ {
+ fprintf(stderr, "Can't create pthread keys. Major malfunction!\n");
+ exit(1);
+ }
+ /* Create threads after we've done all the epoll setup. */
+ for (uint32_t i= 0; i < ms_setting.nthreads; i++)
+ {
+ ms_create_worker(ms_worker_libevent, (void *)&ms_thread_ctx[i]);
+ }
+} /* ms_thread_init */