Home Units Hierarchy Routines All identifiers

Class unaThread

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type unaThread = class(unaObject)

Description

unaThread

Hierarchy

Overview

Methods

Public constructor create(active: bool = false; priority: int = THREAD_PRIORITY_NORMAL );
Public function getHandle(): tHandle;
Public function getThreadId(): unsigned;
Public function pause(): bool;
Public function resume(): bool;
Public class function shouldStopThread(globalID: unsigned): bool;
Public function sleepThread(value: tTimeout): bool;
Public function start(timeout: tTimeout = 10000): bool;
Public function stop(timeout: tTimeout = tTimeout(INFINITE); force: bool = false): bool;
Public function waitForExecute(timeout: tTimeout = 3000): bool;
Public function waitForTerminate(timeout: tTimeout = 3000): bool;
Protected function execute(globalIndex: unsigned): int; virtual;
Protected function grantStart(): bool; virtual;
Protected function grantStop(): bool; virtual;
Protected function onPause(): bool; virtual;
Protected function onResume(): bool; virtual;
Public procedure AfterConstruction(); override;
Public procedure askStop();
Public procedure BeforeDestruction(); override;
Public procedure wakeUp();
Protected procedure setDefaultStopTimeout(value: tTimeout);
Protected procedure startIn(); virtual;
Protected procedure startOut(); virtual;

Properties

Public property globalIndex: unsigned read f_globalThreadIndex;
Public property onExecute: unaThreadOnExecuteMethod read f_onExecute write f_onExecute;
Public property priority: int read getPriority write setPriority;
Public property shouldStop: bool read getShouldStop;
Public property status: unaThreadStatus read getStatus write doSetStatus;

Description

Methods

Public constructor create(active: bool = false; priority: int = THREAD_PRIORITY_NORMAL );

Creates new thread if active is true. If active is false thread will be created by calling the start() method.

Parameters
priority
specifies thread priority.
autoFree
If true thread instance will be freed just after thread exit
Public function getHandle(): tHandle;
 
Returns

Thread handle.

Public function getThreadId(): unsigned;
 
Returns

Thread ID

Public function pause(): bool;

Suspends thread execution.

Public function resume(): bool;

Resumes thread execution.

Public class function shouldStopThread(globalID: unsigned): bool;

Returns true if thread with specified ID was marked to termination.

Public function sleepThread(value: tTimeout): bool;

Pauses the thread for specified amount of milliseconds. Pause may be interrupted by resume(), start(), wakeUp() and stop() mehtods.

Returns

True if pause was interruped, false otherwise.

Public function start(timeout: tTimeout = 10000): bool;

Starts the thread.

Public function stop(timeout: tTimeout = tTimeout(INFINITE); force: bool = false): bool;

Stops the thread.

Public function waitForExecute(timeout: tTimeout = 3000): bool;

Wait till thread enters execute method.

Public function waitForTerminate(timeout: tTimeout = 3000): bool;

Wait till thread is terminated.

Protected function execute(globalIndex: unsigned): int; virtual;

This method will be called when execution starts in a new thread. Override this method in your own threads. Return value indicates result code of thread execution. You must check the shouldStop property periodically in your code. When shouldStop is set to true this function should return as soon as possible.

Protected function grantStart(): bool; virtual;

Called just before execute() method. Should return true unless it is not desired to continue the execution of a thread.

Protected function grantStop(): bool; virtual;

Called just before shouldStop property will be set to true. Should return true unless it is not desired to stop the thread execution.

Protected function onPause(): bool; virtual;
 
Protected function onResume(): bool; virtual;
 
Public procedure AfterConstruction(); override;
 
Public procedure askStop();

Notifies the thread it should be stopped ASAP.

Public procedure BeforeDestruction(); override;

Destroys the thread. If thread is running, stops it by calling the stop() method.

Public procedure wakeUp();

If thread has entered the sleepThread() state, wakes the thread up, making the sleepThread() method to return True. Otherwise simply sets the internal sleep event to signaled state.

Protected procedure setDefaultStopTimeout(value: tTimeout);
 
Protected procedure startIn(); virtual;

Called just before execute() method from thread's context.

Protected procedure startOut(); virtual;

Called just after execute() method from thread's context.

Properties

Public property globalIndex: unsigned read f_globalThreadIndex;

Thread index in internal array.

Public property onExecute: unaThreadOnExecuteMethod read f_onExecute write f_onExecute;

Fires when execution starts in a new thread. See comments for execute() method for details.

Public property priority: int read getPriority write setPriority;

Specifies the priority of the thread.

Public property shouldStop: bool read getShouldStop;

True when thread should be stopped.

Public property status: unaThreadStatus read getStatus write doSetStatus;

Thread status

(c) 2012 Lake of Soft


Generated by PasDoc 0.12.1 on 2012-10-09