Opened 3 years ago

Last modified 5 months ago

#5874 new task

Threading improvements — at Version 10

Reported by: wraitii Owned by:
Priority: Must Have Milestone: Work In Progress
Component: Core engine Keywords:
Cc: Patch: Phab:D3848

Description (last modified by phosit)

We currently use std::thread in a number of places:

Currently uses the threadpool

  • map generator
  • pathfinder

There are issues with our implementation: we use "naked" std::thread instead of cleverer solutions. This, notably, means we fail to detect exceptions happening in the threads (see https://code.wildfiregames.com/rP22649#45341 ) A better architecture ought to be found and implemented.

Change History (10)

comment:2 by wraitii, 3 years ago

Description: modified (diff)
Milestone: Alpha 24Alpha 25

Net client was threaded in A24, A25 will hopefully thread the pathfinder.

comment:3 by Imarok, 3 years ago

Patch: Phab:D3848

comment:4 by wraitii, 3 years ago

In 25656:

Implement a global task manager using a pool of worker threads

Tasks are simple callables (e.g. lambdas), and can be pushed with 2 priority levels. Pushing a task returns a future.
Futures can be waited on, can return results, and can be cancelled deterministically. Futures can also not be waited on.

This gives 'hardware concurrency - 1' threads to maximize CPU usage in a work-stealing workflow.

Reviewed by: vladislavbelov

Refs #5874

Differential Revision: https://code.wildfiregames.com/D3848

comment:5 by Stan, 3 years ago

Description: modified (diff)

comment:6 by Stan, 3 years ago

Milestone: Alpha 25Alpha 26

comment:7 by Stan, 2 years ago

Milestone: Alpha 26Alpha 27

Unlikely to get done for A26

comment:8 by jprahman, 2 years ago

@wraitii @stanislas69 what sorts of remaining improvements do we see here? Have some interest in looking at this. Have a fair bit of experience with system programming/threading from my day job.

in reply to:  8 comment:9 by wraitii, 2 years ago

Replying to jprahman:

@wraitii @stanislas69 what sorts of remaining improvements do we see here? Have some interest in looking at this. Have a fair bit of experience with system programming/threading from my day job.

Well, plenty of systems aren't threaded and _could_ be threaded.If you check the last commits of https://github.com/wraitii/0ad/commits/__THREADPOOL, you'll see some ways to thread some systems, such as sound.

More generally, threading is interesting in general as a speedup, though there are limitations on what you can do in 0 A.D.

comment:10 by phosit, 21 months ago

Description: modified (diff)

Add link to differentials

Note: See TracTickets for help on using tickets.