Compare commits
No commits in common. "319779a16c8ab7483af23f8e5dbbc2346f74ee17" and "eb5a23761d20a76cadbb49732996b04905961c8e" have entirely different histories.
319779a16c
...
eb5a23761d
33
main.c
33
main.c
@ -71,43 +71,13 @@ static size_t threads_parallel(LVM *lvm, void *ud, size_t argn, set_LValueU *hea
|
|||||||
lvm_reset_regs(&set);
|
lvm_reset_regs(&set);
|
||||||
lvm_call(lvm, func, 0, heap, &set);
|
lvm_call(lvm, func, 0, heap, &set);
|
||||||
|
|
||||||
// This thread must still respond to the GC
|
|
||||||
while(atomic_load(&ctx.finished) != no - 1) {
|
while(atomic_load(&ctx.finished) != no - 1) {
|
||||||
lvm->safepoint_func(lvm, heap, regset);
|
lvm->safepoint_func(lvm, heap, regset);
|
||||||
thrd_yield();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ThreadsRunCtx {
|
|
||||||
LVM *L;
|
|
||||||
LFunc *func;
|
|
||||||
};
|
|
||||||
static int threads_run_worker(void *arg) {
|
|
||||||
struct ThreadsRunCtx *ctx = arg;
|
|
||||||
|
|
||||||
LRegSet regs = {};
|
|
||||||
lvm_reset_regs(®s);
|
|
||||||
lvm_run(ctx->L, ctx->func, 0, ®s);
|
|
||||||
|
|
||||||
free(ctx);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static size_t threads_run(LVM *lvm, void *ud, size_t argn, set_LValueU *heap, LRegSet *regset) {
|
|
||||||
LFunc *func = (LFunc*) (regset->regs[0].u & ~LTAG_MASK);
|
|
||||||
|
|
||||||
struct ThreadsRunCtx *ctx = calloc(1, sizeof(*ctx));
|
|
||||||
ctx->L = lvm;
|
|
||||||
ctx->func = func;
|
|
||||||
|
|
||||||
thrd_t thrd;
|
|
||||||
thrd_create(&thrd, threads_run_worker, ctx);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char* read_full_file(const char *fn) {
|
static char* read_full_file(const char *fn) {
|
||||||
FILE *f = fn ? fopen(fn, "rb") : stdin;
|
FILE *f = fn ? fopen(fn, "rb") : stdin;
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
@ -142,9 +112,6 @@ int main(int argc, char **argv) {
|
|||||||
ltable_set(threads,
|
ltable_set(threads,
|
||||||
lvalue_from_string(lstring_newz("parallel")),
|
lvalue_from_string(lstring_newz("parallel")),
|
||||||
lvalue_from_func(lvm_func_from_native(threads_parallel, NULL)));
|
lvalue_from_func(lvm_func_from_native(threads_parallel, NULL)));
|
||||||
ltable_set(threads,
|
|
||||||
lvalue_from_string(lstring_newz("run")),
|
|
||||||
lvalue_from_func(lvm_func_from_native(threads_run, NULL)));
|
|
||||||
}
|
}
|
||||||
ltable_set(env,
|
ltable_set(env,
|
||||||
lvalue_from_string(lstring_newz("threads")),
|
lvalue_from_string(lstring_newz("threads")),
|
||||||
|
1
parse.c
1
parse.c
@ -1072,7 +1072,6 @@ bool parse_stat(Parser *P) {
|
|||||||
|
|
||||||
Scope *new_scope = calloc(1, sizeof(*new_scope));
|
Scope *new_scope = calloc(1, sizeof(*new_scope));
|
||||||
new_scope->parent = P->scope;
|
new_scope->parent = P->scope;
|
||||||
P->scope = new_scope;
|
|
||||||
|
|
||||||
expect(P, TOK_DO);
|
expect(P, TOK_DO);
|
||||||
parse_chunk(P);
|
parse_chunk(P);
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
done = false
|
|
||||||
|
|
||||||
threads.run(function()
|
|
||||||
for i = 1, 100000 do
|
|
||||||
print(i)
|
|
||||||
end
|
|
||||||
done = true
|
|
||||||
end)
|
|
||||||
|
|
||||||
while done == false do
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user