Skip to content

Commit

Permalink
Mark the multi-threading interface as experimental, warns users for p…
Browse files Browse the repository at this point in the history
…otential hard deprecation
  • Loading branch information
Clemapfel committed Feb 3, 2023
1 parent c67dbf6 commit 9b80f2f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions .src/multi_threading.inl
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ namespace jluna
{
_value = std::move(other._value);
other._value = nullptr;
return *this;
}

inline void Task<void>::join()
Expand Down
10 changes: 9 additions & 1 deletion docs/multi_threading.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ Given this, we can immediately throw out using any of the C++ `std::thread`-rela

All is not lost, however: jluna offers its own multi-threading framework, allowing for parallel execution of truly arbitrary C++ code - even if that code interacts with the Julia state.

> **NOTE**: As of 02/2023, Julias current stable release (1.8.5) does not have foreign thread support, as of the merge of
https://github.com/JuliaLang/Julia/pull/45447, however, julia 1.9.x will support foreign therads. This may vastly change
how the jluna multi-threading interface works, for example the section above may no longer apply. Once the foreign threat
support becomes part of the stable Julia release, jlunas multi-threading interface may be removed, deprecated or reworked completely.
Because of this, any function mentioned in this section should be considered **experimental** and, unlike with most of jlunas other
features, continuity between versions is not guaranteed.


### Initializing the Julia Threadpool

In Julia, we have to decide the number of threads we want to use **before startup**.
Expand All @@ -79,7 +87,7 @@ If left unspecified, jluna will initialize Julia with exactly 1 thread. We can s
using namespace jluna;

initialize(JULIA_NUM_THREADS_AUTO);
// equivalent to `julia -t auto`
// equivalent to `Julia -t auto`
```
This sets the number of threads to number of local CPUs, just like [setting environment variable `JULIA_NUM_THREADS` to `auto`](https://docs.julialang.org/en/v1/manual/multi-threading/#Starting-Julia-with-multiple-threads) would do for pure Julia.
Expand Down
7 changes: 6 additions & 1 deletion include/multi_threading.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ namespace jluna
template<typename>struct TaskValue;
}

/// @brief the result of a thread
/// @brief The result of a thread
/// @note jlunas multi-threading interface should be considered experimental and may be deprecated and/or marked for removal once Julia 1.9 releases
template<typename Value_t>
class Future
{
Expand Down Expand Up @@ -86,6 +87,8 @@ namespace jluna
std::unique_ptr<Value_t> _value;
};

/// @brief wrapper around a Julia `Task`, concurrently executed
/// @note jlunas multi-threading interface should be considered experimental and may be deprecated and/or marked for removal once Julia 1.9 releases
template<typename Result_t>
class Task
{
Expand Down Expand Up @@ -145,6 +148,7 @@ namespace jluna
/// @brief threadpool that allows scheduled C++-side tasks to safely access the Julia State from within a thread.
/// Pool cannot be resized, it will use the native Julia threads to execute any C++-side tasks
/// @note during task creation, the copy ctor will be invoked for all arguments `args` and the functions return value. To avoid this, wrap the type in an std::ref
/// @note jlunas multi-threading interface should be considered experimental and may be deprecated and/or marked for removal once Julia 1.9 releases
class ThreadPool
{
template<typename>
Expand Down Expand Up @@ -198,6 +202,7 @@ namespace jluna
};

/// @brief pause the current task, has to be called from within a task allocated via ThreadPool::create
/// @note jlunas multi-threading interface should be considered experimental and may be deprecated and/or marked for removal once Julia 1.9 releases
void yield();
}

Expand Down

0 comments on commit 9b80f2f

Please sign in to comment.