49.4 Overview of the Thread Interfaces

The various thread interfaces manipulate thread objects, application threads, anonymous threads, and keys. The following sections group the functions by these tasks and briefly describe them.

49.4.1 Application Thread Functions

Application threads can be joinable, detached, or daemon threads. You schedule application threads for work when you call a thread create function. The following functions manage application threads:

Purpose

Pthread Equivalent

UI Equivalent

NKS Function

Binds or unbinds a thread from a specified CPU.

NXThreadBind

Retrieves the current CPU binding for the calling thread.

NXThreadGetBinding

Marks the specified thread for termination. The termination occurs when the thread reaches a library cancellation point. Normal termination is done with an exit function.

pthread_cancel

NXThreadDestroy

Causes the thread to exit. If the thread is a detached thread, all its resources are cleaned up. If the thread is a joinable thread, all its resources are not cleaned up until it reports or until the application exits.

pthread_exit

thr_exit

NXThreadExit

Converts a joinable thread to a detached thread.

pthread_detach

NXThreadDetach

Joins the specified thread to the calling thread. The calling thread waits for the specified thread to exit.

pthread_join

thr_join

NXThreadJoin

Retrieves state information for the specified thread.

pthread_attr_getstacksize pthread_attr_getstackaddr pthread_attr_getdetachstate

NXThreadGetContext

Retrieves the thread ID for the calling thread.

pthread_self

thr_self

NXThreadGetId

Retrieves the priority of the thread.

pthread_getschedparam

thr_getprio

NXThreadGetPriority

Sets the priority of the specified thread. Currently, these functions do nothing because the scheduler in the NetWare operating system runs all threads at the same priority.

pthread_setschedparam

thr_setprio

NXThreadSetPriority

Once you schedule an application thread, you can allow it to finish its work, or you can call one of the following functions to interrupt the work:

Purpose

Pthread Equivalent

UI Equivalent

NKS Function

Changes the context of the calling thread to the specified context. Because the context contains all the data for the work, swapping context changes the work of the thread.

NXThreadSwapContext

Suspends the thread's work. The thread stays in this state until a continue function is called, which places the thread back on the run queue. A thread cannot suspend itself.

thr_suspend

NXThreadSuspend

Causes a suspended thread to be placed on the run queue so it can resume its processing.

thr_continue

NXThreadContinue

Causes the calling thread to sleep for specified interval.

NXThreadDelay

Causes the specified thread to stop processing while it waits for an application-defined interrupt to be processed.

pthread_kill

thr_sigsetmask

NXThreadInterrupt

Either checks on the interrupt status of a thread or retrieves the application-defined interrupts for processing.

NXThreadIsInterrupted

Allows the kernel scheduler to determine whether the calling thread should yield its processor to another thread. If no other threads are scheduled to run or if the scheduler determines that the thread has not run long enough, calling this function has no effect.

pthread_yield

thr_yield

NXThreadYield

49.4.2 Key-Value Pair Functions

The following functions manage keys and their data.

Purpose

Pthread Equivalent

UI Equivalent

NKS Function

Creates a key and optionally associates a value with the key for the calling thread and context pair.

pthread_key_create

thr_keycreate

NXKeyCreate

Deletes the specified key. Normally, keys should be destroyed only when an application exits and should not be destroyed by calling this function.

pthread_key_delete

NXKeyDelete

Retrieves the value.

pthread_getspecific

thr_getspecific

NXKeyGetValue

Sets the value.

pthread_setspecific

thr_setspecific

NXKeySetValue

49.4.3 Attribute Object and Context Management Functions

UI threads do not have a separate object for managing the attributes of the thread, but both pthreads and NKS threads do. The pthread attribute object and the NKS thread context have functions which allow you to manage some of the same attributes.

The following pthread functions manage the pthread attribute object.

Pthread Function

Description

pthread_attr_init

Creates a thread attribute object by specifying the stack size, the priority, and the type.

pthread_attr_destroy

Frees the thread attribute object, releasing all of its resources.

pthread_attr_getdetachstate pthread_attr_setdetachstate

Sets and gets the state (detached or joinable) of the thread.

pthread_attr_getinheritsched pthread_attr_setinheritsched

Sets and gets the policy for inheriting scheduling. Currently, LibC supports only the explicit setting of scheduling.

pthread_attr_getname_np pthread_attr_setname_np

Sets and gets a name for the thread. This is useful during debugging because the name appears in the NetWare system debugger.

pthread_attr_getschedpolicy pthread_attr_setschedpolicy

Sets and gets the scheduling policy for the thread. Currently, LibC supports only a FIFO scheduling policy.

pthread_attr_getschedparam pthread_attr_setschedparam

Sets and gets the scheduled priority of the thread.

pthread_attr_getscope pthread_attr_setscope

Sets and gets the scope attribute. Currently, LibC supports only the process scope.

pthread_attr_getstackaddr pthread_attr_setstackaddr

Sets and gets the stack address for the thread.

pthread_attr_getstacksize pthread_attr_setstacksize

Sets and gets the stack size for the thread.

The following NKS functions create and manage NKS thread contexts.

NKS Function

Description

NXContextAlloc

Creates a context by specifying some work to do, the stack size, the priority, and the type.

NXContextFree

Frees a context, releasing all of its resources.

NXContextGet

Retrieves the context for the calling thread.

NXContextGetName

Gets the name of the specified context. A context is not automatically given a name at creation. A name must be set with NXContextSetName.

NXContextSetName

Provides the specified context with a name. This is useful during debugging because the name appears in the NetWare system debugger.

NXContextReinit

Reinitializes a context. All values but the stack size can be modified.

49.4.4 Anonymous Thread Functions

You schedule anonymous threads for work when you call the following NKS functions:

Function

Description

NXLwWorkSchedule

Schedules lightweight work. Lightweight work has no context and is always single-shot.

NXLwWorkCancel

Cancels lightweight work.

NXWorkSchedule

Schedules single-shot work with a specified context.

NXDelayedWorkSchedule

Schedules work to be executed with a specified context at a specified time or at a specified interval.

NXWorkCancel

Cancels periodic or single-shot work.

Neither pthreads or UI threads have anonymous threads that process work. Although you can cancel a thread with pthread_cancel, this type of cancel is not the same as cancelling work. In NKS, you can only cancel work that is not currently running. Periodic work is cancelled by not putting it back on the run queue. Single-shot work is cancelled only if it is still in the run queue.