2021-04-08 11:02:23 +08:00
|
|
|
#include "awtk.h"
|
|
|
|
#include "tkc/data_reader_factory.h"
|
|
|
|
#include "tkc/data_writer_factory.h"
|
|
|
|
#include "tkc/data_writer_file.h"
|
|
|
|
#include "tkc/data_writer_wbuffer.h"
|
|
|
|
#include "tkc/data_reader_file.h"
|
|
|
|
#include "tkc/data_reader_mem.h"
|
|
|
|
#include "base/data_reader_asset.h"
|
|
|
|
#include "conf_io/app_conf_init_json.h"
|
|
|
|
|
2021-04-08 14:01:34 +08:00
|
|
|
#define NR 10000
|
2021-04-08 11:02:23 +08:00
|
|
|
|
|
|
|
static void* work_thread(void* args) {
|
|
|
|
uint32_t i = 0;
|
|
|
|
uint32_t id = (uint32_t)tk_pointer_to_int(args);
|
2021-04-20 18:25:27 +08:00
|
|
|
|
2021-04-08 11:02:23 +08:00
|
|
|
log_debug("%u start\n", id);
|
2021-04-20 18:25:27 +08:00
|
|
|
for (i = 0; i < NR; i++) {
|
2021-04-08 11:02:23 +08:00
|
|
|
app_conf_set_int("test.int", i);
|
|
|
|
app_conf_set_double("test.int", i);
|
|
|
|
app_conf_set_str("test.str", "foo");
|
|
|
|
log_debug("%u run %u\n", id, i);
|
|
|
|
}
|
2021-04-20 18:25:27 +08:00
|
|
|
|
2021-04-08 11:02:23 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
uint32_t i = 0;
|
|
|
|
tk_thread_t* threads[100];
|
|
|
|
|
|
|
|
platform_prepare();
|
|
|
|
data_writer_factory_set(data_writer_factory_create());
|
|
|
|
data_reader_factory_set(data_reader_factory_create());
|
|
|
|
data_writer_factory_register(data_writer_factory(), "file", data_writer_file_create);
|
|
|
|
data_reader_factory_register(data_reader_factory(), "file", data_reader_file_create);
|
|
|
|
data_reader_factory_register(data_reader_factory(), "asset", data_reader_asset_create);
|
|
|
|
data_reader_factory_register(data_reader_factory(), "mem", data_reader_mem_create);
|
|
|
|
data_writer_factory_register(data_writer_factory(), "wbuffer", data_writer_wbuffer_create);
|
|
|
|
|
|
|
|
app_conf_init_json("app_conf_multi_thread");
|
|
|
|
app_conf_set_int("test.int", 100);
|
|
|
|
app_conf_save();
|
|
|
|
|
2021-04-20 18:25:27 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(threads); i++) {
|
2021-04-08 11:02:23 +08:00
|
|
|
threads[i] = tk_thread_create(work_thread, tk_pointer_from_int(i));
|
|
|
|
tk_thread_start(threads[i]);
|
|
|
|
}
|
2021-04-20 18:25:27 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(threads); i++) {
|
2021-04-08 11:02:23 +08:00
|
|
|
tk_thread_join(threads[i]);
|
|
|
|
tk_thread_destroy(threads[i]);
|
|
|
|
log_debug("%u stop\n", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|