Get off my thread: Techniques for moving k to background threads
background threads Anthony Williams Just Software Solutions Ltd https://www.justsoftwaresolutions.co.uk September 2020Get off my thread: Techniques for moving work to background threads Why do we need thread? We don’t just need to move the work, we need to prevent blocking on our event-handling threads. void event_handler(){ auto handle=spawn_background_task(); handle.wait(); // no benefit }Aside: executorSpawning new threads There are lots of ways to spawn new threads: std::thread std::jthread std::async(std::launch::async,...) Platform-specific APIsSpawning new threads There are lots of ways0 码力 | 90 页 | 6.97 MB | 5 月前3Back to Basics: Concurrency
std::thread library. We will introduce topics with pragmatic code examples introducing the ideas of threads and locks, and showing how these programming primitives enable concurrency. In addition, we will conditional variables, promises/futures). Attendees will leave this session being able to use threads, locks, and start thinking about architecting multithreaded software. All materials and code samples time ○ The ‘main thread’ is where our program starts ■ We may then have 1 or more additional threads: ● executing a block of code ● executing other functions ● And overall--sharing the same code0 码力 | 141 页 | 6.02 MB | 5 月前3Concurrency
happen on different threads https://en.cppreference.com/w/cpp/thread/counting_semaphoreCppCon 2023 9 David Olsen - Back to Basics: Concurrency CONCURRENCY “Multiple logical threads of execution with DefinitionCppCon 2023 10 David Olsen - Back to Basics: Concurrency CONCURRENCY “Multiple logical threads of execution with unknown inter-task dependencies” – Daisy Hollman, “A Unifying Abstraction for “Multiple logical threads of execution with [some] inter-task dependencies” DefinitionCppCon 2023 12 David Olsen - Back to Basics: Concurrency CONCURRENCY “Multiple logical threads of execution with0 码力 | 160 页 | 2.91 MB | 5 月前3Rethinking Task Based Concurrency and Parallelism for Low Latency C++
meticulously designed lock-free queues experience a significant drop in performance as the number of threads increases. ● Multiple sub-queues can be used to mitigate contention but this introduces a myriad of other shortcomings which further complicate issues ● By their nature, queues bring tasks to threads: ○ Requiring tasks to convey both data and logic ○ Often leading to task class hierarchies, pointers contracts in the group) ● Threads are brought to the “task” rather than the “task” being brought to the threads (as is done with Task Queues) ○ Minimize thread contention because threads do not compete for the0 码力 | 142 页 | 2.80 MB | 5 月前3Deciphering C++ Coroutines
mental model for coroutines: Cooperative Threads void spawn_task () { // ... Result r = outer_function (); }16/55 A mental model for coroutines: Cooperative Threads void spawn_task () { // ... Result r Cooperative Threads PartialResult middle_function () { auto r = inner_function (); return PartialResult :: from_io_result (r); }16/55 A mental model for coroutines: Cooperative Threads PartialResult function() inner function() Task18/55 Threads - A straightforward solution std::futurespawn_task () { return std:: async( outer_function ); }18/55 Threads - A straightforward solution main() 0 码力 | 156 页 | 1.79 MB | 5 月前3Julia 1.12.0 RC1
multiple threads . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 25.2 Threadpools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 25.3 The @threads Macro . . . . . . . . . . . . . . . . . . . . . . . . . 324 25.4 Communication and data-races between threads . . . . . . . . . . . . . . . . . . . 326 25.5 Side effects and mutable function arguments . . new method definition won't be visible to the current runtime environment, including Tasks and Threads (and any previously defined @generated functions). Let's start with an example to see what this0 码力 | 2057 页 | 7.44 MB | 3 月前3julia 1.13.0 DEV
multiple threads . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 25.2 Threadpools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 25.3 The @threads Macro . . . . . . . . . . . . . . . . . . . . . . . . . 324 25.4 Communication and data-races between threads . . . . . . . . . . . . . . . . . . . 326 25.5 Side effects and mutable function arguments . . new method definition won't be visible to the current runtime environment, including Tasks and Threads (and any previously defined @generated functions). Let's start with an example to see what this0 码力 | 2058 页 | 7.45 MB | 3 月前3Julia 1.12.0 Beta4
multiple threads . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 25.2 Threadpools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 25.3 The @threads Macro . . . . . . . . . . . . . . . . . . . . . . . . . 324 25.4 Communication and data-races between threads . . . . . . . . . . . . . . . . . . . 326 25.5 Side effects and mutable function arguments . . new method definition won't be visible to the current runtime environment, including Tasks and Threads (and any previously defined @generated functions). Let's start with an example to see what this0 码力 | 2057 页 | 7.44 MB | 3 月前3Julia 1.12.0 Beta3
multiple threads . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 25.2 Threadpools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 25.3 The @threads Macro . . . . . . . . . . . . . . . . . . . . . . . . . 324 25.4 Communication and data-races between threads . . . . . . . . . . . . . . . . . . . 326 25.5 Side effects and mutable function arguments . . new method definition won't be visible to the current runtime environment, including Tasks and Threads (and any previously defined @generated functions). Let's start with an example to see what this0 码力 | 2057 页 | 7.44 MB | 3 月前3julia 1.12.0 beta1
multiple threads . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 25.2 Threadpools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 25.3 The @threads Macro . . . . . . . . . . . . . . . . . . . . . . . . . 324 25.4 Communication and data-races between threads . . . . . . . . . . . . . . . . . . . 326 25.5 Side effects and mutable function arguments . . new method definition won't be visible to the current runtime environment, including Tasks and Threads (and any previously defined @generated functions). Let's start with an example to see what this0 码力 | 2047 页 | 7.41 MB | 3 月前3
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 100