char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Masato Nakasakacommon: Intentionally leak logger instance to fix hanging on Windows (#22273)7b95ea5d1

char/aliceai-t5-moe
1.3 KiB43 linesraw
1#include "log.h"
2
3#include <cstdlib>
4#include <thread>
5
6int main() {
7    const int n_thread = 8;
8
9    std::thread threads[n_thread];
10    for (int i = 0; i < n_thread; i++) {
11        threads[i] = std::thread([i]() {
12            const int n_msg = 1000;
13
14            for (int j = 0; j < n_msg; j++) {
15                const int log_type = std::rand() % 4;
16
17                switch (log_type) {
18                    case 0: LOG_INF("Thread %d: %d\n", i, j); break;
19                    case 1: LOG_WRN("Thread %d: %d\n", i, j); break;
20                    case 2: LOG_ERR("Thread %d: %d\n", i, j); break;
21                    case 3: LOG_DBG("Thread %d: %d\n", i, j); break;
22                    default:
23                        break;
24                }
25
26                if (rand () % 10 < 5) {
27                    common_log_set_timestamps(common_log_main(), rand() % 2);
28                    common_log_set_prefix    (common_log_main(), rand() % 2);
29                }
30            }
31        });
32    }
33
34    for (int i = 0; i < n_thread; i++) {
35        threads[i].join();
36    }
37
38    common_log_flush(common_log_main());
39    // We explicitly free the logger singleton to avoid hanging on Windows
40    // related to timing issues of thread startup and DLL teardown
41    common_log_free(common_log_main());
42    return 0;
43}