# How is concurrency runtime set up before a program's main is called?

**URL:** <https://forums.swift.org/t/how-is-concurrency-runtime-set-up-before-a-programs-main-is-called/88367>\
**Category:** Using Swift\
**Tags:** concurrency-runtime\
**Created:** [July 19, 2026, 12:30am UTC](https://forums.swift.org/t/how-is-concurrency-runtime-set-up-before-a-programs-main-is-called/88367 "2026-07-19T00:30:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibex](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ibex/32/30439_2.png) [@ibex](https://forums.swift.org/u/ibex)\
**Post date:** [July 19, 2026, 12:30am UTC](https://forums.swift.org/t/how-is-concurrency-runtime-set-up-before-a-programs-main-is-called/88367/1 "2026-07-19T00:30:08Z")

</div>

I use the following code to start things rolling in my command line programs:

```swift
@main
enum Driver {
   static func main () async throws {
       // Start rolling...
   }
}

```

Could anyone shed some light on what calls the `Driver.main` and what takes place before the call? Even better, please point me to the relevant code where this happens.

---

<div class="post-metadata">

**Author:** ![MahdiBM](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mahdibm/32/45271_2.png) [@MahdiBM](https://forums.swift.org/u/MahdiBM)\
**Post date:** [July 19, 2026, 11:42am UTC](https://forums.swift.org/t/how-is-concurrency-runtime-set-up-before-a-programs-main-is-called/88367/2 "2026-07-19T11:42:01Z")

</div>

I haven't looked into that so perhaps someone else can tell, but I wonder if you could be more clear about what exactly you're looking for.

The reason is, I don't think on a Swift level, much happens before calling main. Sure maybe some concurrency related stuff (run the global executor? start some threads? not sure if some are started up front or are all lazy-initialized), but, not much.

It's similar to asking what happens before calling `int main(int argc, char *argv[])` in C/C++. Where, again, not much happens. The kernel loads the app into memory typically after calling one of the `exec` functions, likely after the parent process forks itself, and calls the entry point of the app (the main func). Now in Swift, Swift itself probably does a bit of work before calling the main func, I'm assuming, but again, it should amount to "not much".

So basically I'm wondering if you actually are looking to know what that "not much" is, or you're looking for something else, or perhaps, both.

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [July 19, 2026, 1:27pm UTC](https://forums.swift.org/t/how-is-concurrency-runtime-set-up-before-a-programs-main-is-called/88367/3 "2026-07-19T13:27:18Z")

</div>

Godbolt is really good for these kinds of explorations.

For a normal, non-throwing synchronous `main`, there's not much going on. Swift generates a C-calling convention `main`, which calls a synthesized static `$main` method on your `@main` type, which calls the actual `main` that you wrote ([link](https://godbolt.org/z/aGc31sb1o)).

A throwing `main` is similar but it has to do a little bit more work to prepare for a possible error being thrown, and if your `main` does then it calls a runtime function to report the error and exit abnormally.

For an `async` main, there's [quite a bit more](https://godbolt.org/z/8szGeYaxz) that happens before your `main` gets called, since it has to set up the concurrency runtime, put your `main` in a `Task`, and wait for it to complete.

EDIT: I forgot to mention what happens before the C `main` entry point is called, but that's dependent on the startup code used by your target platform, and not typically something you need to be concerned about unless you're doing embedded work.

Furthermore, the lack of features like C++ static constructors in Swift means you don't have to worry about random (Swift) code in your binary executing before your `main` does. _However_, the Swift runtime _itself_ does have some code that uses ` __attribute__ ((constructor))` to initialize itself, to handle things like the global protocol conformance lookup tables.

---

<div class="post-metadata">

**Author:** ![ibex](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ibex/32/30439_2.png) [@ibex](https://forums.swift.org/u/ibex)\
**Post date:** [July 20, 2026, 12:22am UTC](https://forums.swift.org/t/how-is-concurrency-runtime-set-up-before-a-programs-main-is-called/88367/4 "2026-07-20T00:22:07Z")

</div>

> [@MahdiBM](#):
>
> So basically I'm wondering if you actually are looking to know what that "not much" is, or you're looking for something else, or perhaps, both.

Thank you, and I am sorry for being vague.

I want to explore how the `concurrency runtime` is set up before the `main` is called.

I am going to edit the title of the post. 🙂

---

<div class="post-metadata">

**Author:** ![ibex](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ibex/32/30439_2.png) [@ibex](https://forums.swift.org/u/ibex)\
**Post date:** [July 20, 2026, 12:23am UTC](https://forums.swift.org/t/how-is-concurrency-runtime-set-up-before-a-programs-main-is-called/88367/5 "2026-07-20T00:23:30Z")

</div>

> [@allevato](#):
>
> Godbolt is really good for these kinds of explorations.

> [@allevato](#):
>
> For an `async` main, there's [quite a bit more](https://godbolt.org/z/8szGeYaxz) that happens before your `main` gets called, since it has to set up the concurrency runtime, put your `main` in a `Task`, and wait for it to complete.

Thank you.
