| | 1680 | // NOTE: This loop is necessary to avoid a race between newly created |
|---|
| | 1681 | // threads and the GC. If a collection starts between the time |
|---|
| | 1682 | // Thread.start is called and the new thread calls Thread.add, |
|---|
| | 1683 | // the thread could manipulate global state while the collection |
|---|
| | 1684 | // is running, and by being added to the thread list it could be |
|---|
| | 1685 | // resumed by the GC when it was never suspended, which would |
|---|
| | 1686 | // result in an exception thrown by the GC code. An alternative |
|---|
| | 1687 | // would be to have Thread.start call Thread.add for the new |
|---|
| | 1688 | // thread, but this introduces its own problems, since the |
|---|
| | 1689 | // thread object isn't entirely ready to be operated on by the |
|---|
| | 1690 | // GC. This could be fixed by tracking thread startup status, |
|---|
| | 1691 | // but it's far easier to simply have Thread.add wait for any |
|---|
| | 1692 | // running collection to stop before altering the thread list. |
|---|
| | 1693 | |
|---|