# Current

* this pointer denotes the current running task on a CPU.
* it is accessible only in process context and not interrupts.
* it is defined in `<arch/x86/include/asm/current.h>` for x86 processors

```c
static __always_inline struct task_struct *get_current(void)
{
	if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT))
		return this_cpu_read_const(const_pcpu_hot.current_task);

	return this_cpu_read_stable(pcpu_hot.current_task);
}
```

* returns `task_struct` for the current task running on the CPU

> `this_cpu_read_const` and `this_cpu_read_stable` are used to obtain per-cpu variables. More information is given at `<arch/x86/include/asm/percpu.h>`

```
this_cpu_read() makes gcc load the percpu variable every time it is
accessed while this_cpu_read_stable() allows the value to be cached.
this_cpu_read_stable() is more efficient and can be used if its value
is guaranteed to be valid across cpus.  The current users include
pcpu_hot.current_task and pcpu_hot.top_of_stack, both of which are
actually per-thread variables implemented as per-CPU variables and
thus stable for the duration of the respective task.
```

The source code here is taken from `linux-6.8.1`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lagnos.gitbook.io/linux-kernel-notes/misc/current.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
