context_new - Linux


context_new creates a new context in the current thread. A context is a container for a group of related tasks, and it allows you to control the execution of those tasks.


int context_new(context_t *ctx, int stack_size);
  • ctx: A pointer to a context_t structure. This structure will store the context information.
  • stack_size: The size of the stack for the new context. This value must be a multiple of 8.


There are no options or flags for context_new.


The following example creates a new context:

context_t ctx;
int stack_size = 8192;

if (context_new(&ctx, stack_size) != 0) {

Once a context has been created, you can use the context_switch function to switch to it.

Common Issues

One common issue is trying to use a context that has not been created. This will cause a segmentation fault.

Another common issue is trying to switch to a context that is already running. This will also cause a segmentation fault.


context_new can be used with other Linux commands and tools to create advanced tasks. For example, you can use context_new to create a new thread that runs a specific function.

Related Commands

  • context_switch: Switches to the specified context.
  • context_destroy: Destroys the specified context.