1 Introduction

About trivial-main-thread

Sometimes it is absolutely necessary to run certain tasks in the main thread of the implementation. This is particularly the case with GUI applications on OS X, where only thread 0 is allowed to issue drawing calls. This library aims to help with that.

Why a Wrapper

Why not just call bt:interrupt-thread and be done with it? Well, an implementation is not required to provide the user with the main thread, and may instead choose to use it for its own purposes. For example, CCL uses the thread for housekeeping and signal handling. As such, some implementations require workarounds to make this go by smoothly. That's why this library exists.

Basic Usage

Load trivial-main-thread through ASDF or Quicklisp.

(ql:quickload :trivial-main-thread)

Now you can simply issue calls to be sent to the main thread by using call-in-main-thread or with-body-in-main-thread.

Upon first usage of either of these two functions, trivial-main-thread will start a new thread to resume the main thread's functionality in if necessary, and interrupt the main thread with a task runner loop. From then on, call requests can be sent to the thread. For more information on the tasks and runners system, see simple-tasks.

For example, if you wanted to start a Qt application, you could do the following:

If the MAIN-THREAD is EQL to BT:CURRENT-THREAD, then the RUNNER is
CHANGE-CLASSed into SIMPLE-TASK:RUNNER. This runner class does not
use threading and instead directly executes the tasks. If we did not
do this, situations where the main thread is the currently evaluating
thread, we would block it forever, and thus stop it from ever reaching
any task scheduling calls.