# STasks

The stask library is used to implement tasks, which need to be executed in a seperate thread, but can be used as normal asynchronous tasks. This is useful for functions, for which in the respective operating system environment, no assynchronus APIs are available.

The tasks_file library uses this library

The implementation to handle the seperate threads is operating system dependend. For linux this implementation is done in linux/stask/stask_threas.cpp/h

## File information

File | common/interface/stask.h
Classes | STask STaskContext STaskThread

# Classes

## STask

    class STask : public ITask, public UIoExec {
        void IoExec(void * execContext);

        class STaskContext * context;
        dword progress;

    protected:
        void TaskComplete();
        void TaskFailed();
        void TaskProgress(dword progress = 0);

        class STaskThread * thread;

    public:
        STask(class STaskContext * context);
        void Start(class UTask * user);
        virtual void SStart() = 0;
    };

This class is used as base class for the implementation of the synchronous task. It provides the standard ITask interface.

STask(class STaskContext * context)

Contruktor of the task. It needs a pointer to a STaskContext, which must be allocated in the application, typically as base class to the instance class.

void Start(class UTask * user)

The Start function is called by the application to start the task (same as with task.h). It is implemented operating system dependend to allocate a thread to execute the task. For Linux it is implemented in common/linux/stask_theads.cpp/h.

virtual void SStart() = 0

Virtual function implemented for the specific task. This function is called in the context of a worker thread to do the synchronous execution of the task.

void TaskComplete(), void TaskFailed(), void TaskProgress(dword progress = 0)

These functions are implemented operating system dependent and are called by the synchrounus implementation of the task so that the respective class UTask functions are called in the context of the instance thread.

## STaskContext

    class STaskContext {
    public:
        STaskContext(class IIoMux * iomux) {
            this->iomux = iomux;
        };

        class IIoMux * iomux;
        istd::list<STaskThread> threadsIdle;
        istd::list<STaskThread> threadsBusy;
    }

STask internal task, used to manage the available threads. Typically used as base class of the instance class

## STaskThread

    class STaskThread : public istd::listElement<STaskThread> {
    public:
        virtual void startTask(class STask * task) = 0;
        virtual void wait() = 0;
        virtual void cont() = 0;
    }

Task used as base class for the operating system dependend task management.