raz / test / run / ThreadOverflowC.raz

27 lines · 580 B · raw · history · last change f871b244

1module ThreadOverflowC;
2(* A stack overflow in a thread of a program that uses C is told as
3 one in the main thread is: Thread gives C's thread a stack for the
4 signal handlers. One frame bigger than any stack C gives a thread. *)
5import Thread, C;
6
7proc big: I64;
8var pad: [64 * 1024 * 1024]U8;
9begin
10 pad[0] := 1;
11 return I64(pad[0]);
12end;
13
14proc work(_arg: ^U8);
15begin
16 _ := big();
17end;
18
19proc main*;
20var t: ^Thread.Thread; e: ERROR;
21begin
22 _ := C.getpid();
23 t, e := Thread.spawn(work, nil);
24 if e = nil then Thread.join(t); end;
25end;
26
27end ThreadOverflowC.