summaryrefslogtreecommitdiffstats
path: root/src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c
blob: 69e125d407d04eebbf309f4fc3dc662ce3e215f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 */

#ifndef __wasi__
#error This example only compiles to WASM/WASI target
#endif

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

#include "wasi_thread_start.h"

enum CONSTANTS {
    SECOND = 1000 * 1000 * 1000, /* 1 second */
    TIMEOUT = 1LL * SECOND
};

typedef struct {
    start_args_t base;
} shared_t;

void
__wasi_thread_start_C(int thread_id, int *start_arg)
{
    /* Wait so that the exception is raised after the main thread has finished
     * already */
    __builtin_wasm_memory_atomic_wait32(NULL, 0, TIMEOUT);
    __builtin_trap();
}

int
main(int argc, char **argv)
{
    shared_t data = { 0 };

    assert(start_args_init(&data.base));
    int thread_id = __wasi_thread_spawn(&data);
    assert(thread_id > 0 && "Thread creation failed");

    return EXIT_SUCCESS;
}