Tasklet
Object Hierarchy:
Description:
public class Tasklet : Object
A Tasklet instance represents a thread that has been spawned to execute a
certain function.
In order to spawn a thread to execute a method of an object proceed this way:
* prepare a function, or a static method, with the signature void *(*)(void *)
* prepare a struct which will contain:
* * the instance of the class which the method is invoked in,
* * the parameters (simple types or objects) that will be passed.
* in the function do this:
* * cast the void* to a pointer to your struct
* * if you pass a ref-counted class, assign it to a local variable in order to increase the refcounter
* * if you pass a simple type, assign it to a local variable in order to copy its value
* * call Tasklet.schedule_back() in order to let the caller decide when to start the new thread
* * call the method with the object and parameters that you just copied in local variables
* when you want to spawn, allocate in the stack a struct of the type
* populate the struct with data
* call Tasklet.spawn(function, &my_struct)
The real function/method will not start immediately, but the struct can be safely freed right now.
Features:
* method schedule gives a chance to the scheduler to assign the cpu to other threads;
* method schedule can select a particular tasklet to be scheduled;
* method schedule_back schedules the previous tasklet;
* method join waits for a thread to complete and can get a void* from it;
* ...
Namespace: Ntk.Lib
Package: vd
Content:
Properties:
Static methods:
- public static void tasklet_leaves (
string
reason = "")
- public static void tasklet_regains (
string
reason = "")
- public static
bool
init ()
- public static
bool
kill ()
Kills immediately the threading system.
- public static void exit_current_thread (void* val)
Exits the current thread.
- public static void exit_app (
int
val)
Waits for all the threads to complete and then kills the threading
system and exits the application.
- public static void schedule (Tasklet? next = null)
- public static void schedule_back ()
- public static Tasklet self ()
- public static void nap (
long
sec, long
usec)
- public static
int
system (string
? command)
- public static
bool
equal_func (Tasklet a, Tasklet b)
- public static
uint
hash_func (Tasklet a)
- public static Tasklet spawn (FunctionDelegate function, void* params_tuple_p,
bool
joinable = false, int
stacksize = -1)
- public static void cancel_point ()
Methods: