# link: prevent deadlock when prelink tasks fail · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/e17a050bc695f7d117b89adb1d258813593ca111)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: e17a050bc695f7d117b89adb1d258813593ca111

Requested commit: e17a050bc695f7d117b89adb1d258813593ca111

Commit: e17a050bc695f7d117b89adb1d258813593ca111

Tree: f281876485848c783fb9e2a10616b98cda0b2e09

Author: mlugg

Committer: Matthew Lugg

## Message

```
link: prevent deadlock when prelink tasks fail

If an error occured which prevented a prelink task from being queued,
then `pending_prelink_tasks` would never be decremented, which could
cause deadlocks in some cases. So, instead of calculating ahead of time
the number of prelink tasks to expect, we use a simpler strategy which
is much like a wait group: we add 1 to a value when we spawn a worker,
and in the worker function, `defer` decrementing the value. The initial
value is 1, and there's a decrement after all of the workers are
spawned, so once it hits 0, prelink is done (be it with a failure or a
success).

```

## Parents

- [3de8bbd3d4e262df11a582fb52401b8077b5f352](https://git.cafe/gitcafe/zig/commit/3de8bbd3d4e262df11a582fb52401b8077b5f352?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/e17a050bc695f7d117b89adb1d258813593ca111?format=markdown)
