| 1 | module 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. *) |
| 5 | import Thread, C; |
| 6 | |
| 7 | proc big: I64; |
| 8 | var pad: [64 * 1024 * 1024]U8; |
| 9 | begin |
| 10 | pad[0] := 1; |
| 11 | return I64(pad[0]); |
| 12 | end; |
| 13 | |
| 14 | proc work(_arg: ^U8); |
| 15 | begin |
| 16 | _ := big(); |
| 17 | end; |
| 18 | |
| 19 | proc main*; |
| 20 | var t: ^Thread.Thread; e: ERROR; |
| 21 | begin |
| 22 | _ := C.getpid(); |
| 23 | t, e := Thread.spawn(work, nil); |
| 24 | if e = nil then Thread.join(t); end; |
| 25 | end; |
| 26 | |
| 27 | end ThreadOverflowC. |