Skip to content

AThread#

Represents a user-defined thread.

Header:#include <AUI/Thread/AThread.h>
CMake:aui_link(my_target PUBLIC aui::core)

Public Types#

Interrupted#


class AThread::Interrupted

Exception that is thrown by AThread::interruptionPoint(), if interruption is requested for this thread. Handled by AThread::start.

Empty structure.

Public Methods#

current#


static const _<AAbstractThread>& AThread::current()
Returns
current thread.

Examples#

examples/app/game_of_life/src/main.cpp

Game of Life - Game of Life implementation that uses advanced large dynamic data rendering techniques such as ITexture, AImage to be GPU friendly. The computation is performed in AThreadPool.

    _<ITexture> mTexture;

    void updateTexture() {
        if (!mTexture) {
            mTexture = AWindow::current()->getRenderingContext()->renderer().getNewTexture();
        }

        CellsImage image(mCells->size());
        for (unsigned y = 0; y < image.height(); ++y) {
            for (unsigned x = 0; x < image.width(); ++x) {
examples/ui/contacts/src/view/ContactDetailsView.cpp

AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.

        return;
    }

    // discard
    if (AMessageBox::show(dynamic_cast<AWindow*>(AWindow::current()), "Do you really want to discard?", "This action is irreversible!", AMessageBox::Icon::NONE, AMessageBox::Button::YES_NO) != AMessageBox::ResultButton::YES) {
        return;
    }
    mContact = mOriginalContact;
    mEditorMode = false;
}
examples/7guis/cells/src/Spreadsheet.h

7GUIs Cells - Spreadsheet processor (Excel).

        struct RangeIterator {
            const Spreadsheet* spreadsheet;
            formula::Range range;
            glm::uvec2 current;

            RangeIterator operator++() {
                current.x += 1;
                if (current.x <= range.to.x) {
                    return *this;
examples/7guis/circle_drawer/src/main.cpp

7GUIs Circle Drawer - Undo, redo, dialog control.

                  [this, circle] {


                      auto radiusPopup = _new<AWindow>(
                          "", 200_dp, 50_dp, dynamic_cast<AWindow*>(AWindow::current()), WindowStyle::MODAL);
                      radiusPopup->setContents(Vertical {
                        Label { "Adjust diameter of circle at {}."_format(circle->position) },
                        _new<ASlider>() AUI_LET {
                                it->setValue(circle->radius / MAX_RADIUS);
                                connect(

interruptionPoint#


static void AThread::interruptionPoint()

Interruption point

If the interruption flag is raised for the caller thread then flag is reset and AThread::Interrupted exception is thrown, efficiently stopping the task execution and safely freeing resources with C++'s RAII feature.

AUI_THREADPOOL, AUI_THREADPOOL_X, AThreadPool::enqueue, AUI_ENTRY handle AThread::Interrupted, so throwing AThread::Interrupted is safe.

join#


void AThread::join()

Waits for thread to be finished.

main#


static const _<AAbstractThread>& AThread::main()

Returns main thread of the application.

processMessages#


static void AThread::processMessages()

Processes messages from other threads of current thread. Called by framework itself using IEventLoop.

setName#


static void AThread::setName(AString name)
Arguments
name
new name of the thread

Sets name of the current thread for debugger.

sleep#


static void AThread::sleep(std::chrono::milliseconds duration)

Sleep for specified duration. Most operation systems guarantee that elasped time will be greater than specified. AThread::interrupt() is supported.

Arguments
duration
sleep duration.

start#


void AThread::start()

Start thread execution.

Examples#

examples/7guis/timer/src/main.cpp

7GUIs Timer - Timer example.

          },
        });

        connect(mTimer->fired, me::update);
        mTimer->start();
    }

private:
    _<ATimer> mTimer = _new<ATimer>(100ms);
    high_resolution_clock::time_point mStartTime = high_resolution_clock::now();