Thread Handling

 

See Also: ucNewThread, ucExprThread, ucReleaseItem

 

 

Apartment-model threads

 

uCalc Fast Math Parser allows you to group definitions and evaluations into independent threads. Whatever you define or evaluate in one thread group is invisible to other thread groups. To allocate a new thread group, use ucNewThread. This will return a handle that you can pass as the last argument to functions such as ucParse, ucDefine, ucDefineFunction, ucDefineVariable, etc.

 

 

Classes and Objects

 

You can re-organize functions in the include file into a class. The details will vary from compiler to compiler. But generally, when the class is constructed, you should call ucNewThread to obtain a handle for the object instance. ucParse, ucDefine, etc., should each be defined as members of the class, and you should use the thread handle with each of these functions. When the class instance is destroyed, you should call ucReleaseItem with the handle of the thread.

 

 

Current Thread

 

A native callback routine can retrieve the handle of the current thread that called it, using ucExprThread.

 

 

Releasing a thread

 

You can release a thread using ucReleaseItem with the handle of the thread. This will de-allocate all definitions associated with the thread. This can be compared to version 2.0's ucReset routine, except only the given thread is released. When you release a thread, all of its sub-threads are also released. Generally, it is best to avoid releasing the default thread, which is where the default functions and operators are defined.

 

 

Example:

 

Visual Basic

' Default (parent) thread definition

ucDefine "Const: Pi = Atan(1)*4"

 

' Thread A definitions

tHandle_A = ucNewThread()

ucDefineFunction "COSINE(x) = COS(x)", 0, tHandle_A

ucDefineVariable "IndyVar = 20", 0, tHandle_A

 

' Thread B definitions

tHandle_B = ucNewThread()

ucDefineFunction "COSINE(x) = COS(x * Pi / 180)", 0, tHandle_B

ucDefineVariable "IndyVar = 50", 0, tHandle_B

 

' Printout

Print ucEval("Pi"), ucEval("Pi", tHandle_A), ucEval("Pi", tHandle_B)

Print ucEval("IndyVar"), ucEval("IndyVar", tHandle_A), ucEval("IndyVar", tHandle_B)

Print ucEval("COSINE(60)"), ucEval("COSINE(60)", tHandle_A), ucEval("COSINE(60)", tHandle_B)

 

If you run the above example, you will get the following results:

 

Expression Default thread Thread A Thread B

Pi 3.14159... 3.14159... 3.14159...

IndyVar Undefined 20 50

COSINE(60) Undefined -0.95241... 0.5

 

New or enhanced in version 3.0

         Nothing related to this topic.

         See What's New in version 3.0.

 

New or enhanced in version 2.96