| 1 | module ThreadOverflow; |
| 2 | (* A stack overflow in a thread is told as one in the main thread is: |
| 3 | the thread's mapping holds a stack for the signal handlers *) |
| 4 | import Thread; |
| 5 | |
| 6 | proc down(n: I64): I64; |
| 7 | var pad: [64]I64; |
| 8 | begin |
| 9 | pad[n mod 64] := n; |
| 10 | return down(n + 1) + pad[0]; |
| 11 | end; |
| 12 | |
| 13 | proc work(_arg: ^U8); |
| 14 | begin |
| 15 | _ := down(0); |
| 16 | end; |
| 17 | |
| 18 | proc main*; |
| 19 | var t: ^Thread.Thread; e: ERROR; |
| 20 | begin |
| 21 | t, e := Thread.spawn(work, nil); |
| 22 | if e = nil then Thread.join(t); end; |
| 23 | end; |
| 24 | |
| 25 | end ThreadOverflow. |