Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runlloop usage #4

Open
diggit opened this issue Aug 28, 2018 · 1 comment
Open

Runlloop usage #4

diggit opened this issue Aug 28, 2018 · 1 comment
Labels

Comments

@diggit
Copy link
Contributor

diggit commented Aug 28, 2018

Hi,
I am a little bit confused by Runloop usage.

  • Can you explain some simple usecase?
  • What is the advantage of using thread+runllop+timer instead of putting function call into thread with sleep?
@flit
Copy link
Owner

flit commented Sep 2, 2018

Hi @diggit, runloops are a semi-experimental feature that are partially derived from runloops on macOS and iOS (and NeXTStep before then).

They currently serve two purposes:

  • timer control
  • waiting on multiple queues

The benefit of a real timer object instead of using sleep or sleep_until is that you can easily have multiple timers with different timeouts running on the same thread, as well as mixed one-shot and periodic timers. In most RTOSes, all timers run on a single, low-priority timer thread. Using runloops for timers in Argon gives you control over timer priority at the expense of having to create your own thread+runloop.

Any number of queues can also be linked to a runloop. If a linked queue receives an item, the runloop will exit and tell you which queue received so you can read the item and process it.

For a specific use case, runloops work very nicely for UI threads, i.e., for event- or message-handling threads that may need to perform some periodic work of their own.

I'm open to ideas for improving runloops! (And I'll move some of this explanatory text into the doxygen docs.)

@flit flit added the faq label Sep 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants