Commit 6d62084
authored
Auto merge of #36341 - sagebind:thread_id, r=alexcrichton
Add ThreadId for comparing threads
This adds the capability to store and compare threads with the current calling thread via a new struct, `std::thread::ThreadId`. Addresses the need outlined in issue #21507.
This avoids the need to add any special checks to the existing thread structs and does not rely on the system to provide an identifier for a thread, since it seems that this approach is unreliable and undesirable. Instead, this simply uses a lazily-created, thread-local `usize` whose value is copied from a global atomic counter. The code should be simple enough that it should be as much reliable as the `#[thread_local]` attribute it uses (however much that is).
`ThreadId`s can be compared directly for equality and have copy semantics.
Also see these other attempts:
- #29457
- #29448
- #29447
And this in the RFC repo: rust-lang/rfcs#14351 file changed
+59
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
169 | 170 | | |
170 | 171 | | |
171 | 172 | | |
| |||
524 | 525 | | |
525 | 526 | | |
526 | 527 | | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
527 | 567 | | |
528 | 568 | | |
529 | 569 | | |
530 | 570 | | |
531 | 571 | | |
532 | 572 | | |
533 | 573 | | |
| 574 | + | |
534 | 575 | | |
535 | 576 | | |
536 | 577 | | |
| |||
551 | 592 | | |
552 | 593 | | |
553 | 594 | | |
| 595 | + | |
554 | 596 | | |
555 | 597 | | |
556 | 598 | | |
| |||
569 | 611 | | |
570 | 612 | | |
571 | 613 | | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
572 | 620 | | |
573 | 621 | | |
574 | 622 | | |
| |||
977 | 1025 | | |
978 | 1026 | | |
979 | 1027 | | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
980 | 1039 | | |
981 | 1040 | | |
982 | 1041 | | |
0 commit comments