NXWorkSchedule

Schedules the specified work to be executed by an anonymous thread.

Library:LibC
Classification:NKS
Service:Threads

Syntax

  #include <nks/thread.h>
   
  int NXWorkSchedule (
     NXContext_t   ctx, 
     NXBool_t      bind,
     NXWorkId_t   *wid);
  

Parameters

ctx

(IN) Specifies the work to be scheduled. The context must be of type NX_CTX_WORK (see NXContextAlloc).

bind

(IN) Specifies whether the work should be bound to the current CPU:

  • TRUE The work should be bound to the CPU on which this function is called. This is a suggestion, which the system is free to ignore.
  • FALSE No binding is specified.
wid

(OUT) Points to the ID of the scheduled work. This ID can subsequently be used to delete the work (see NXWorkCancel).

Return Values

If successful, returns 0; otherwise, returns a nonzero error code:

Decimal

Hex

Constant

Description

9

0x09

NX_EINVAL

The specified context is invalid.

24

0x18

NX_EAGAIN

Insufficient resources to complete the call.

62

0x3E

NX_EBUSY

The specified context is already in use.

Remarks

The only way to determine if it is safe to reschedule work is to cancel the work using synchronous cancel. Unfortunately, if you cancel the work when the work has yet to begin execution, the work will get canceled and will not be executed. However, if work has already begun execution, it will not be aborted and cancel will return when the work finally completes.

NKS work functions are different from NetWare work-to-do functions. With NetWare functions, it is possible to reschedule a work item once it has already begun executing. However, NKS functions allow you to reschedule a work context only if it has completed execution. An executing work context cannot reschedule itself. If you want the NetWare style of work scheduling, you should use the NKS light-weight work functions.

If you call NXThreadExit during the execution of a work context or if the thread that is executing the work context returns from the function that is specified in the work context, the work context is reset and is available for reuse by the application.

If a request for a binding is to be meaningful, you should be in a nonpreemptible context or you must be bound to the CPU on which the function is called.

See Also