Skip to content

Instantly share code, notes, and snippets.

@JobLeonard
Created December 15, 2014 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JobLeonard/42c3d430a3b0a848d79e to your computer and use it in GitHub Desktop.
Save JobLeonard/42c3d430a3b0a848d79e to your computer and use it in GitHub Desktop.
Sleepsort in Céu
class SleepSorter with
var int t;
do
await (t)ms;
_printf("%d ", t);
end
par/or do
var SleepSorter[100000] sorter with
this.t = (_rand()%100);
end;
await FOREVER;
with
_printf("\n");
every 1ms do
_printf("\n");
end
with
await 101ms;
end
escape 0;
@fsantanna
Copy link

Sorry, couldn't resist suggesting modifications :)

class SleepSorter with
    var int t;
do
    await (t)us;  // microseconds is the smallest unit Ceu supports
    _printf("%d ", t);
end

// The par/or not required:

// the organism starts here
var SleepSorter[100000] sorter with
    this.t = (_rand()%100);
end;
// and is still in scope here (no need for a dedicated block w/ an "await FOREVER")

 _printf("\n");
watching 101us do  // watching also works for events
    every 1us do
        _printf("\n");
   end
end

@JobLeonard
Copy link
Author

Hah, thanks! Apparently Gist doesn't send a notification if there's a comment, didn't see this before :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment