| 1 | # Dex |
| 2 | |
| 3 | Dex provides Future-based programming for GLib-based applications. |
| 4 | |
| 5 | It both integrates with and brings new features for application and library |
| 6 | authors who want to structure concurrent code in an easy to manage way. |
| 7 | |
| 8 | Dex also provides Fibers which allow writing synchronous looking code in C |
| 9 | that uses asynchronous and future-based APIs. |
| 10 | |
| 11 | Dex is licensed as LGPL-2.1+. |
| 12 | |
| 13 | ## Documentation |
| 14 | |
| 15 | You can find |
| 16 | [documentation for Dex](https://gnome.pages.gitlab.gnome.org/libdex/libdex-1/index.html) |
| 17 | updated as part of the CI pipeline. |
| 18 | |
| 19 | ## Building |
| 20 | |
| 21 | Dex requires GLib 2.68 or newer but can likely be ported to older versions. |
| 22 | For those interested, you can add missing API to `dex-compat-private.h`. |
| 23 | |
| 24 | Some examples require additional libraries but will not be compiled if the |
| 25 | libraries are unavailable while building. |
| 26 | |
| 27 | Use Meson to build the project. |
| 28 | |
| 29 | ```sh |
| 30 | $ cd libdex/ |
| 31 | $ meson setup build . --prefix=/usr |
| 32 | $ cd build/ |
| 33 | $ ninja |
| 34 | $ ninja test |
| 35 | ``` |
| 36 | |
| 37 | You can build for Windows using mingw which is easy on Fedora Linux, or |
| 38 | using Visual Studio 2022 17.5 or later, or with `clang-cl`. Building with |
| 39 | Visual Studio or `clang-cl` would involve using a Visual Studio command |
| 40 | prompt and running something like what is done on UNIX platforms above, |
| 41 | and setting the envvars `CC` and `CXX` to point to `clang-cl` if needed. |
| 42 | |
| 43 | ```sh |
| 44 | $ sudo dnf install mingw64-gcc mingw64-glib2 |
| 45 | $ cd libdex/ |
| 46 | $ meson setup build-win64 . --cross-file=/usr/share/mingw/toolchain-mingw64.meson |
| 47 | $ cd build/ |
| 48 | $ ninja |
| 49 | |
| 50 | # You can test using wine, but will need access to libraries |
| 51 | $ cd /usr/x86_64-w64-mingw32/sys-root/mingw/bin/ |
| 52 | $ wine $builddir/examples/tcp-echo.exe |
| 53 | ``` |
| 54 | |
| 55 | ## Supported Platforms |
| 56 | |
| 57 | * Linux |
| 58 | * macOS |
| 59 | * FreeBSD |
| 60 | * Windows |
| 61 | * Illumos |
| 62 | |
| 63 | ## Library Versioning |
| 64 | |
| 65 | Libdex follows a somewhat modern library scheme of GNOME libraries. |
| 66 | Before libdex 1.0, an odd semantic minor number indicated unstable releases. |
| 67 | From 1.0 on, the minor number does not have such meaning. |
| 68 | The micro number now indicates alpha, beta, and rc for release-candidates. |
| 69 | |
| 70 | ## More Information |
| 71 | |
| 72 | You can read about why this is being created and what led to it over the |
| 73 | past two decades of contributing to GNOME and GTK. |
| 74 | |
| 75 | * https://blogs.gnome.org/chergert/2022/11/24/concurrency-parallelism-i-o-scheduling-thread-pooling-and-work-stealing/ |
| 76 | * https://blogs.gnome.org/chergert/2022/12/13/threading-fibers/ |
| 77 | * https://blogs.gnome.org/chergert/2022/12/16/dex-examples-and-windows-support/ |
| 78 | |
| 79 | ## Projects using Libdex |
| 80 | |
| 81 | These projects may serve as inspiration for how to use Libdex. |
| 82 | |
| 83 | * https://gitlab.gnome.org/GNOME/foundry |
| 84 | * https://gitlab.gnome.org/GNOME/sysprof |
| 85 | * https://gitlab.gnome.org/GNOME/manuals |
| 86 | * https://gitlab.gnome.org/GNOME/gnome-builder |
| 87 | |
| 88 | ## Implementation Notes |
| 89 | |
| 90 | While Dex is using GObject and GIO, it implements its own fundamental type |
| 91 | (DexObject) for which all other types inherit. Given the concurrent and |
| 92 | parallel nature of futures and the many situations to support, it is the |
| 93 | authors opinion that the performance drawbacks of such a flexible type as |
| 94 | GObject is too costly. By controlling the feature-set to strictly what is |
| 95 | necessary we can avoid much of the slow paths in GObject. |
| 96 | |
| 97 | You wont notice much of a difference though, as types are generally defined and |
| 98 | used very similarly to GObject's but with different macro names. |
| 99 | |
| 100 | You can see this elsewhere in both GStreamer and GTK 4's render nodes. |
| 101 | |
| 102 | ## Terminology |
| 103 | |
| 104 | * **Future** describes something that can either resolve (succeed) or |
| 105 | reject (fail) now or in the future. It's resolved/rejected value is |
| 106 | immutable after completing. |
| 107 | * **Resolved** indicates that a future has completed successfully and |
| 108 | provided a value which can be read by the consumer. |
| 109 | * **Rejected** indicates that a future has completed with failure and |
| 110 | provided an error which can be read by the consumer. |
| 111 | * **Promise** is a **Future** that allows user code to set the resolved |
| 112 | or rejected value once. |
| 113 |