Skip to content

Commit

Permalink
Merge branch 'boostorg:develop' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed May 31, 2024
2 parents 540b663 + a9ebaf9 commit 17c1d9e
Show file tree
Hide file tree
Showing 61 changed files with 1,565 additions and 219 deletions.
2 changes: 2 additions & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ deps = [
'libs/assert',
'libs/beast',
'libs/bind',
'libs/callable_traits',
'libs/chrono',
'libs/circular_buffer',
'libs/concept_check',
'libs/config',
'libs/container',
'libs/context',
'libs/core',
'libs/date_time',
'libs/detail',
Expand Down
39 changes: 34 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
cxxstd: "20,2b"
os: macos-13
stdlib: libc++
cobalt_pmr: boost-container

runs-on: ${{matrix.os}}
container: ${{matrix.container}}
Expand Down Expand Up @@ -97,8 +98,10 @@ jobs:
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python3 tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
git submodule update --init libs/test
# Temporary workaround
git submodule update --init libs/callable_traits
git submodule update --init libs/context
git submodule update --init libs/chrono
git submodule update --init libs/ratio
Expand Down Expand Up @@ -165,6 +168,8 @@ jobs:
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
git submodule update --init libs/test
# temporary workaround,
git submodule update --init libs/callable_traits
git submodule update --init libs/context
git submodule update --init libs/chrono
git submodule update --init libs/ratio
cmd /c bootstrap
Expand All @@ -183,12 +188,16 @@ jobs:
include:
- os: ubuntu-22.04
shared: OFF
boost-container: 0
- os: ubuntu-22.04
shared: ON
boost-container: 0
- os: macos-13
shared: OFF
boost-container: 1
- os: macos-13
shared: ON
boost-container: 1

runs-on: ${{matrix.os}}

Expand Down Expand Up @@ -221,14 +230,16 @@ jobs:
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
git submodule update --init libs/test
# Temporary workaround
git submodule update --init libs/callable_traits
git submodule update --init libs/context
git submodule update --init libs/chrono
git submodule update --init libs/ratio
- name: Use library with add_subdirectory
run: |
cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test
mkdir __build__ && cd __build__
cmake -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
cmake -DBUILD_SHARED_LIBS=${{matrix.shared}} -DBOOST_COBALT_USE_BOOST_CONTAINER=${{matrix.boost-container}} ..
cmake --build .
ctest --output-on-failure --no-tests=error
Expand All @@ -239,12 +250,16 @@ jobs:
include:
- os: ubuntu-22.04
shared: OFF
boost-container: 0
- os: ubuntu-22.04
shared: ON
boost-container: 0
- os: macos-13
shared: OFF
boost-container: 1
- os: macos-13
shared: ON
boost-container: 1

runs-on: ${{matrix.os}}

Expand Down Expand Up @@ -277,6 +292,8 @@ jobs:
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
git submodule update --init libs/test
# Temporary workaround
git submodule update --init libs/callable_traits
git submodule update --init libs/context
git submodule update --init libs/chrono
git submodule update --init libs/ratio
Expand All @@ -285,7 +302,7 @@ jobs:
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=${{matrix.shared}} -DBOOST_COBALT_USE_BOOST_CONTAINER=${{matrix.boost-container}} ..
- name: Build
run: |
Expand All @@ -312,12 +329,16 @@ jobs:
include:
- os: ubuntu-22.04
shared: OFF
boost-container: 0
- os: ubuntu-22.04
shared: ON
boost-container: 0
- os: macos-13
shared: OFF
boost-container: 1
- os: macos-13
shared: ON
boost-container: 1

runs-on: ${{matrix.os}}

Expand Down Expand Up @@ -350,14 +371,16 @@ jobs:
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
git submodule update --init libs/test
# Temporary workaround
git submodule update --init libs/callable_traits
git submodule update --init libs/context
git submodule update --init libs/chrono
git submodule update --init libs/ratio
- name: Configure
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON -DBOOST_COBALT_USE_BOOST_CONTAINER=${{matrix.boost-container}} -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
- name: Build tests
run: |
Expand Down Expand Up @@ -403,6 +426,8 @@ jobs:
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
git submodule update --init libs/test
# Temporary workaround
git submodule update --init libs/callable_traits
git submodule update --init libs/context
git submodule update --init libs/chrono
git submodule update --init libs/ratio
Expand Down Expand Up @@ -458,6 +483,8 @@ jobs:
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
git submodule update --init libs/test
# Temporary workaround
git submodule update --init libs/callable_traits
git submodule update --init libs/context
git submodule update --init libs/chrono
git submodule update --init libs/ratio
Expand Down Expand Up @@ -531,8 +558,10 @@ jobs:
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
git submodule update --init libs/test
# Temporary workaround
git submodule update --init libs/callable_traits
git submodule update --init libs/context
git submodule update --init libs/chrono
git submodule update --init libs/ratio
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ if (NOT BOOST_COBALT_IS_ROOT)
target_link_libraries(boost_cobalt
PUBLIC
Boost::asio
Boost::callable_traits
Boost::circular_buffer
Boost::config
Boost::core
Expand Down Expand Up @@ -96,7 +97,7 @@ else()

file(GLOB_RECURSE ADOC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.adoc)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html
COMMAND asciidoctor ${CMAKE_CURRENT_SOURCE_DIR}/doc/index.adoc --require asciidoctor-diagram --require asciidoctor-multipage -b multipage_html5 -o ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html
COMMAND asciidoctor ${CMAKE_CURRENT_SOURCE_DIR}/doc/index.adoc --require asciidoctor-diagram --require asciidoctor-multipage -b multipage_html5 -a generate-diagram -o ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html
DEPENDS ${ADOC_FILES})

add_custom_target(boost_cobalt_doc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html)
Expand Down
2 changes: 1 addition & 1 deletion doc/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import asciidoctor ;

html index.html : index.adoc : <flags>"-r asciidoctor-diagram" ;
html index.html : index.adoc ;

install html_ : index.html : <location>html ;

Expand Down
19 changes: 14 additions & 5 deletions doc/background/lazy_eager.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Coro Done
resumed twice
----


[mermaid]
ifdef::generate-diagram[]
[mermaid, target=lazy_eager1]
----
sequenceDiagram
participant main;
Expand All @@ -54,6 +54,11 @@ sequenceDiagram
lazy->>main: co_return
Note left of main: "resumed twice"
----
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/lazy_eager1.png[]
endif::[]


Whereas an eager coro would look like this:
Expand Down Expand Up @@ -90,8 +95,8 @@ Coro Done
----



[mermaid]
ifdef::generate-diagram[]
[mermaid, target=lazy_eager2]
----
sequenceDiagram
participant main;
Expand All @@ -104,5 +109,9 @@ sequenceDiagram
Note right of lazy: "Coro done"
lazy->>main: co_return
Note left of main: "resumed once"
----
endif::[]

----
ifndef::generate-diagram[]
image::{docdir}/images/lazy_eager2.png[]
endif::[]
17 changes: 15 additions & 2 deletions doc/background/stackless.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ main()
bar()
----

[mermaid]
ifdef::generate-diagram[]
[mermaid, target=stackless1]
----
sequenceDiagram
main->>+foo: call
foo->>+bar: call
bar->>-foo: return
foo->>-main: return
----
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/stackless1.png[]
endif::[]

Coroutines can be implemented a stackful, which means that it allocates a fixes chunk of memory and stacks function frames similar to a thread.
C++20 coroutines are stackless, i.e. they only allocate their own frame and use the callers stack on resumption. Using our previous example:
Expand Down Expand Up @@ -75,7 +81,9 @@ main()
f$example()
----

[mermaid]

ifdef::generate-diagram[]
[mermaid, target=stackless2]
----
sequenceDiagram
participant main
Expand All @@ -89,5 +97,10 @@ sequenceDiagram
main-->>example: resume
example->>-main: co_return
----
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/stackless2.png[]
endif::[]

The same applies if a coroutine gets moved accross threads.
8 changes: 4 additions & 4 deletions doc/design/race.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[#design:race]
== Select
== Race

The most important synchronization mechanism is the `race` function.

Expand Down Expand Up @@ -33,12 +33,12 @@ cobalt::promise<void> p()
}
----

The `race` must however internally wait for all awaitable to complete
The `race` must however internally wait for all awaitable to complete
once it initiates to `co_await`.
Therefor, once the first <<awaitable, awaitable>> completes,
Therefore, once the first <<awaitable, awaitable>> completes,
it tries to <<interrupt_await, interrupt>> the rest, and if that fails cancels them.

`race` is the preferred way to trigger cancellations, e.g:
`race` is the preferred way to trigger cancellations, e.g.:

[source,cpp]
----
Expand Down
Binary file added doc/images/awaitables.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/generators1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/generators2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/lazy_eager1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/lazy_eager2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/stackless1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/stackless2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions doc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Version 0.1, 29.01.2023
:source-language: c++
:example-caption: Example

:imagesdir: {docdir}/images

:leveloffset: +1

Expand Down Expand Up @@ -78,6 +79,9 @@ include::reference/error.adoc[]
include::reference/config.adoc[]
include::reference/leaf.adoc[]

include::reference/experimental/context.adoc[]


= In-Depth

include::background/custom_executors.adoc[]
Expand Down
10 changes: 5 additions & 5 deletions doc/motivation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
Many languages programming languages
like node.js and python provide easy to use single-threaded concurrency frameworks.
While more complex than synchronous code,
single threaded cobalthronicity avoids many of the pitfalls & overhead of multi-threading.
single threaded asynchronicity avoids many of the pitfalls & overhead of multi-threading.

That is, one coroutine can work, while others wait for events (e.g. a response from a server).
This allows to write applications that *do multiple things simultaneously* on a *single thread*.

This library is meant to provide this to C++: *simple single threaded cobalthronicity*
akin to node.js and cobaltio in python that works with existing libraries like
This library is meant to provide this to C++: *simple single threaded asynchronicity*
akin to node.js and asyncio in python that works with existing libraries like
`boost.beast`, `boost.mysql` or `boost.redis`.
It based on `boost.asio`.

It takes a collection of concepts from other languages and provides them based on C++20 coroutines.

- easy asynchronous base functions, such as an cobalt <<main, main>> & <<thread, threads>>
- easy asynchronous base functions, such as an async <<main, main>> & <<thread, threads>>
- <<promise, promise>> & <<generator, generator>> types
- <<op, operation wrappers>>
- an <<with, cobalt scope>>
- an <<with, async scope>>
- <<race, race>>
- <<channel, channel>>

Expand Down
9 changes: 7 additions & 2 deletions doc/primer/awaitables.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ NOTE: Type will be implicitly converted into an awaitable if there is an `operat
This documentation will use `awaitable` to include these types,
and "actual_awaitable" to refer to type conforming to the above prototype.


[mermaid]
ifdef::generate-diagram[]
[mermaid, target=awaitables]
----
flowchart TD
aw{await_ready?}
aw ---->|true| ar[await_resume]
aw -->|false| as[await_suspend]
as -->|Resume| ar
----
endif::[]

ifndef::generate-diagram[]
image::{docdir}/images/awaitables.png[]
endif::[]

In a `co_await` expression the waiting coroutine will first invoke
`await_ready` to check if the coroutine needs to suspend.
Expand Down
Loading

0 comments on commit 17c1d9e

Please sign in to comment.