Skip to content

sleep_sort is incorrect #1

@workingjubilee

Description

@workingjubilee

It has two problems:

  1. thread::sleep does not guarantee wakeup after the sleep time has elapsed. This is impossible to fix... but I must admit, it will tend to work fairly often.
  2. More fixable yet more egregious is that spawning threads takes a nonzero amount of time! Even if it only consumes a few microseconds, this means that takes less than 1000 items being sorted to throw off things by an entire millisecond, which is disastrous to this sorting scheme. In reality, it takes far less, as your tests don't pass on craterbot. All threads should do something like spin on an AtomicBool so that they only commence sleeping when they are all spawned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions