| | @@ -601,3 +601,30 @@ |
| 601 | 601 | |
| 602 | 602 | Met in mosaico's `Mconfig`, where `MenuAction.run` and a status block's |
| 603 | 603 | kind `run` met; the block's kind was renamed `command`. |
| 604 | + |
| 605 | +## A signal to one thread |
| 606 | + |
| 607 | +`Sys.kill` signals a process, and the kernel gives the signal to any |
| 608 | +of its threads that doesn't block it. A program whose thread waits in |
| 609 | +a system call, a read or a `Sys.ready`, has no way to break into that |
| 610 | +wait from another thread: the signal may land on the thread that sent |
| 611 | +it, or on a third. |
| 612 | + |
| 613 | +The proposal, in the library: |
| 614 | + |
| 615 | +``` |
| 616 | +proc signal*(t: ^Thread; sig: INT): INT; (* sig sent to t alone; 0, or minus an errno *) |
| 617 | +``` |
| 618 | + |
| 619 | +in `Thread`, beside `join`: `tgkill(getpid(), t^.tid, sig)` in a |
| 620 | +program without C, `pthread_kill(t^.tid, sig)` in one with C, as |
| 621 | +`Thread` already keeps either id in `tid`. With `Sys.handle(sig)` in |
| 622 | +the program, the wait the thread is in fails with -4, as `^C` makes a |
| 623 | +wait fail on the main thread today. It breaks no program, so it could |
| 624 | +come with any release, not only a thaw. |
| 625 | + |
| 626 | +Met in arno's screen: a turn runs on a thread of its own, reading the |
| 627 | +model's reply with rnet. The human's `C-c` is a key on the loop's |
| 628 | +thread, which can only set a flag that the turn reads after each read |
| 629 | +of the reply; a server that says nothing for a minute, as a model does |
| 630 | +while it thinks, keeps the turn going for that minute. |