# Linux Kernel Module Cheat

##### 24.22.6.2. gem5 `ThreadState`

Owned one per `ThreadContext`.

Many `ThreadContext` methods simply forward to `ThreadState` implementations.

`SimpleThread` inherits from `ThreadState`, and forwards to it on several methods e.g.:

        int cpuId() const override { return ThreadState::cpuId(); }
        uint32_t socketId() const override { return ThreadState::socketId(); }
        int threadId() const override { return ThreadState::threadId(); }
        void setThreadId(int id) override { ThreadState::setThreadId(id); }
        ContextID contextId() const override { return ThreadState::contextId(); }
        void setContextId(ContextID id) override { ThreadState::setContextId(id); }

`O3ThreadContext` on the other hand contains an `O3ThreadState`:

    template <class Impl>
    struct O3ThreadState : public ThreadState

at:

    template <class Impl>
    class O3ThreadContext : public ThreadContext
    {
        O3ThreadState<Impl> *thread

        ContextID contextId() const override { return thread->contextId(); }

        void setContextId(ContextID id) override { thread->setContextId(id); }