What is gcc doing here to run this code once per thread?

What is gcc doing here to run this code once per thread?

I just ran across this technique for running code once per thread. I don't know how it works at the lowest level though. Especially, what's fs pointing to? What does .zero 8 mean? Is there a reason the identifier is @tpoff?

I just ran across this technique for running code once per thread. I don't know how it works at the lowest level though. Especially, what's fs pointing to? What does .zero 8 mean? Is there a reason the identifier is @tpoff?

int foo();

void bar() { thread_local static auto _ = foo(); }

Output (with -O2):

bar():
        cmp     BYTE PTR fs:guard variable for bar()::@tpoff, 0
        je      .L8
        ret
.L8:
        sub     rsp, 8
        call    foo()
        mov     BYTE PTR fs:guard variable for bar()::@tpoff, 1
        add     rsp, 8
        ret
guard variable for bar()::_:
        .zero   8


c++ multithreading

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Multithreading in C#

Multithreading is a parallel way of execution where the application is broken into parts so that it can have more than one execution path at the same time.

Loops in C++ | For, While, and Do While Loops in C++

In this Video We are going to see how to use Loops in C++. We will see How to use For, While, and Do While Loops in C++.

Using isdigit() in C/C++

In this article, we'll take a look at using the isdigit() function in C/C++. This is a very simple way to check if any value is a digit or not. Let's look

C++ Tutorial for Beginners 19 - C++ Structures | Struct declaration | C++ Data Structures

Welcome to this course on C++ Tutorial for Beginners. In this video we will see How to use C++ Structures.

Object Oriented Programming in C++ | C++ OOPs Concepts | Learn Object Oriented C++

C++ is general purpose, compiled, object-oriented programming language and its concepts served as the basis for several other languages such as Java, Python, Ruby, Perl etc.