ScheduleWorkToDo
Schedules a routine as work, which puts it on the highest priority queue, the WorkToDoList
#include <nwthread.h>
int ScheduleWorkToDo (
void (*ProcedureToCall) ( ) ,
void *workData,
WorkToDo *workToDo);
This function schedules work to be executed by an OS worker thread.
The ProcedureToCall parameter points to the procedure to be scheduled as work. Work is a high-priority, low overhead procedure. See When to Schedule a Routine as Work.
The workData parameter contains the data to be passed to ProcedureToCall.
The workToDo parameter is a structure used by CLIB.NLM to set up WorkToDo process scheduling. The structure must be allocated before calling this function and released afterward (for example, by calling malloc and free). Other than allocating workToDo, the developer does not need to be concerned with the details of this stucture since the only user-defined fields in the structure are set by the ProcedureToCall and workData parameters. WorkToDo is defined in nwthread.h.
Since the work that is scheduled is done by an OS worker thread, it is not be able to use the NetWare API functions that use context, unless context is given to the OS worker thread.
The context that is given to the OS worker thread is determined by the value in the registering thread’s context specifier. You can set the context specifier to one of the following options:
Once inside of your callback, you can manually give your callback thread CLIB context by calling SetThreadGroupID and passing in a valid thread group ID. If you manually set up your context, you need to reset its context to its original context, by setting the thread group ID back to its original value.
When a new thread is started with BeginThread, BeginThreadGroup or ScheduleWorkToDo, its context specifier is set to USE_CURRENT_CONTEXT by default.
You can determine the current setting of the registering thread’s context specifier by calling GetThreadContextSpecifier. You use SetThreadContextSpecifier to set the registering thread’s context specifier to one of the above options.
For more information on using CLIB context, see Context Problems with OS Threads.
#include <stdio.h>
#include <nwthread.h>
#include <nwconio.h>
int count = 0;
/*........................*/
void ScreenUpdater(void *data)
{
data = data;
count++;
clrscr();
printf("You could use a work to do thread\n\n");
printf("to do screen updates. %i.\n\n\n", count);
printf("Work to do threads get into the\n\n");
printf("system fast and are useful to\n\n");
printf("accomplish finite definable tasks.");
}
/*........................*/
main()
{
WorkToDo screenWork;
char ch = 0;
SetAutoScreenDestructionMode(TRUE);
while (ch != ’q’)
{
ScheduleWorkToDo(ScreenUpdater, NULL, &screenWork);
/* ThreadSwitch makes sure work to do gets a chance to run. */
ThreadSwitch();
if (!kbhit())
ThreadSwitchWithDelay();
else
ch = getch();
}
}
/*........................*/