ContentsIndex
PreviousUpNext
Thread
Topics | Functions | Structs, Records, Enums | Types
Description

Provides functions for threads, signals and mutex related activities.

Introduction

LinkIt platform is a multi-threaded environment. An application in the LinkIt platform runs on the main thread in the system. An application can call vm_thread_create() to create a sub-thread, with specified priority. The system allows the maximum of 10 sub-threads to be created by the vm_thread_create(). The specified priority is just a proposed priority. The system will assign an actual priority (based on the proposed priority) accordingly to the sub-thread based on the current system resource. The value 1 indicates the highest priority, while the 255 is the lowest. 

If the proposed priority is equal or less than 128, the actual priority assigned by the system will be higher than the main thread. If the proposed priority is equal or greater than 129, the actual thread priority assigned by the system will be lower than the main thread. If the proposed priority value is 0, the system will assign the default priority to the thread, which is lower than priority of the main thread. 

One thread can send messages to another thread through vm_thread_send_message(), or receive messages from another thread through vm_thread_get_message(). 

A thread can create a signal by calling vm_signal_create(), and then post the signal by calling vm_signal_post(), for thread synchronizations. 

The mutex functions are also provided in this module for sharing data among threads safely.

Limitation

The maximum number of threads allowed to be created in the system is 10. APIs in DCL & BSD modules can be invoked in a sub-thread, as they are designed for both the main thread and the sub-thread. The APIs in all other modules should be invoked in the main thread. They should not be invoked in a sub-thread.

Group
Functions
Function 
Description 
Initializes a mutex. 
Locks a mutex, to block the access to the data (objects or variables) protected by the mutex. 
Releases the mutex. The thread that is blocked by the mutex will have the access to the protected objects by the mutex when the mutex is unlocked. 
The ID of the signal which was clean. 
Creates a signal for thread communication. 
Destroys a signal when it is no longer needed, so the resource is released. 
Posts a signal then all the threads, which are waiting for it, will be waken up. 
Waits on a signal. If the signal is not set, the thread will be blocked. When the other thread posts the signal, the waiting threads will be waken up. This API should be used in the threads spawned from vm_thread_create(). If the time out has been reached and the signal is posted yet, the waiting thread will resume the execution. 
Waits on a signal. If the signal is not set, the thread will be blocked. When the other thread posts the signal, the waiting threads will be waken up. This API should only be used in the threads spawned from vm_thread_create(). 
Creates a thread. Limited by the system, vm_thread_create() can only create up to 10 threads. The caller of this function needs to pass the expected priority to the create. The value 1 indicates the highest priority, while the 255 is the lowest. The actual thread priority will be assigned by the system according to the following rule.
 

  1. If the expected priority is equal or less than 128, the actual priority

assigned by the system will be higher than the main thread.

  1. If the expected priority is equal or greater than 129, the actual thread

priority assigned by the system will... more 

Gets the handle of the current thread. Note, this function is not supported in the main thread. 
Get the handle of the main. 
Reads the message from a message queue. This function will be blocked if the message queue is empty. It can only be used in a thread spawned from vm_thread_create(). 
Sends a message to a thread. 
Makes a thread sleep for a number of milliseconds. It should only be used in the threads spawned from vm_thread_create(). Note, putting a thread into the sleep for too long could potentially cause unexpected behavior. If the thread, which is responsible for reading from a message queue, was put into sleep for too long, for example, the message queue might overflow because of too many unprocessed messages. 
Structs, Records, Enums
Struct, Record, Enum 
Description 
A mutex node. Used by system. 
A mutex node. Used by system. 
mutex 
Signal result. 
Thread message. 
Types
Type 
Description 
Signal id, returned by vm_signal_init(). 
Thread main function type, the thread will be closed when it returned. 
Thread handle, returned by vm_thread_create(). 
Thread priority. 
Links
Created with a commercial version of Doc-O-Matic. In order to make this message disappear you need to register this software. If you have problems registering this software please contact us at support@toolsfactory.com.