avoiding switching to Maestro and reading directly the data you're interested
in.
-For simcalls which might block, `kernelSync()` can be used. It takes a
+For simcalls which might block, `kernel_sync()` can be used. It takes a
C++ callback and executes it immediately in maestro. This C++ callback is
expected to return a `simgrid::kernel::Future<T>` reprensenting the operation
in the kernal. When the operations completes, the user process is waken up
~~~
try {
- std::vector<char> result = simgrid::simix::kernelSync([&] {
+ std::vector<char> result = simgrid::simix::kernel_sync([&] {
// Fictional example, simgrid::kernel::readFile does not exist.
simgrid::kernel::Future<std::vector<char>> result = simgrid::kernel::readFile(file);
return result;
});
XBT_DEBUG("Finished reading file %s: length %zu", file, result.size());
}
-// If the operation failed, kernelSync() throws an exception:
+// If the operation failed, kernel_sync() throws an exception:
catch (std::runtime_error& e) {
XBT_ERROR("Could not read file %s", file);
}
~~~
-Asynchronous blocks can be implemented with `kernelAsync()`. It works
-like `kernelSync()` but does not block. Instead, it returns a
+Asynchronous blocks can be implemented with `kernel_async()`. It works
+like `kernel_sync()` but does not block. Instead, it returns a
`simgrid::simix::Future` representing the operation in the process:
~~~
-simgrid::simix::Future<std:vector<char>> result = simgrid::simix::kernelSync([&] {
+simgrid::simix::Future<std:vector<char>> result = simgrid::simix::kernel_sync([&] {
// Fictional example, simgrid::kernel::readFile does not exist.
simgrid::kernek::Future<std::vector<char>> result = simgrid::kernel::readFile(file);
return result;
}
~~~
-<b>Note:</b> `kernelSync(f)` could be implemented as `kernelAsync(f).get()`.
+<b>Note:</b> `kernel_sync(f)` could be implemented as `kernel_async(f).get()`.
\section simgrid_dev_guide_tag What is How to add a new tag for xml files?
`simgrid::simix::unblock(actor)`) when the operation is completed.
This is wrapped in a higher-level primitive as well. The
-`kernelSync()` function expects a function-object which is executed
+`kernel_sync()` function expects a function-object which is executed
immediately in the simulation kernel and returns a `Future<T>`. The
simulator blocks the actor and resumes it when the `Future<T>` becomes
ready with its result:
@code{cpp}
template<class F>
-auto kernelSync(F code) -> decltype(code().get())
+auto kernel_sync(F code) -> decltype(code().get())
{
typedef decltype(code().get()) T;
if (SIMIX_is_maestro())
A contrived example of this would be:
@code{cpp}
-int res = simgrid::simix::kernelSync([&] {
+int res = simgrid::simix::kernel_sync([&] {
return kernel_wait_until(30).then(
[](simgrid::kernel::Future<void> future) {
return 42;
### Asynchronous operations {#uhood_switch_v2_async}
-We can write the related `kernelAsync()` which wakes up the actor immediately
+We can write the related `kernel_async()` which wakes up the actor immediately
and returns a future to the actor. As this future is used in the actor context,
it is a different future
(`simgrid::simix::Future` instead of `simgrid::kernel::Future`)
}
@endcode
-`kernelAsync()` simply :wink: calls `kernelImmediate()` and wraps the
+`kernel_async()` simply :wink: calls `kernelImmediate()` and wraps the
`simgrid::kernel::Future` into a `simgrid::simix::Future`:
@code{cpp}
template<class F>
-auto kernelAsync(F code)
+auto kernel_async(F code)
-> Future<decltype(code().get())>
{
typedef decltype(code().get()) T;
A contrived example of this would be:
@code{cpp}
-simgrid::simix::Future<int> future = simgrid::simix::kernelSync([&] {
+simgrid::simix::Future<int> future = simgrid::simix::kernel_sync([&] {
return kernel_wait_until(30).then(
[](simgrid::kernel::Future<void> future) {
return 42;
int res = future.get();
@endcode
-`kernelSync()` could be rewritten as:
+`kernel_sync()` could be rewritten as:
@code{cpp}
template<class F>
-auto kernelSync(F code) -> decltype(code().get())
+auto kernel_sync(F code) -> decltype(code().get())
{
- return kernelAsync(std::move(code)).get();
+ return kernel_async(std::move(code)).get();
}
@endcode
The semantic is equivalent but this form would require two simcalls
-instead of one to do the same job (one in `kernelAsync()` and one in
+instead of one to do the same job (one in `kernel_async()` and one in
`.get()`).
## Mutexes and condition variables
* the second one is a wait-based (`future.get()`) future used in the actors
which waits using a simcall.
-These futures are used to implement `kernelSync()` and `kernelAsync()` which
+These futures are used to implement `kernel_sync()` and `kernel_async()` which
expose asynchronous operations in the simulation kernel to the actors.
In addition, we wrote variations of some other C++ standard library
* @return Value of the kernel future
* @exception Exception from the kernel future
*/
-template<class F>
-auto kernelSync(F code) -> decltype(code().get())
+template <class F> auto kernel_sync(F code) -> decltype(code().get())
{
typedef decltype(code().get()) T;
if (SIMIX_is_maestro())
});
return result.get();
}
+template <class F>
+XBT_ATTRIB_DEPRECATED_v323("Please use simix::kernel_sync()") auto kernelSync(F code) -> decltype(code().get())
+{
+ return kernel_sync(code);
+}
/** A blocking (`wait()`-based) future for SIMIX processes */
// TODO, .wait_for()
* @param code SimGrid kernel code which returns a simgrid::kernel::Future
* @return Actor future
*/
-template<class F>
-auto kernelAsync(F code)
- -> Future<decltype(code().get())>
+template <class F> auto kernel_async(F code) -> Future<decltype(code().get())>
{
typedef decltype(code().get()) T;
// Wrap the kernel future in a actor future:
return simgrid::simix::Future<T>(std::move(future));
}
-
+template <class F>
+XBT_ATTRIB_DEPRECATED_v323("Please use simix::kernel_sync()") auto kernelAsync(F code) -> Future<decltype(code().get())>
+{
+ return kernel_async(code);
+}
}
}
XBT_INFO("kernel, returned");
// Synchronize on a successful Future<void>:
- simgrid::simix::kernelSync([] {
+ simgrid::simix::kernel_sync([] {
return kernel_wait_until(10).then([](simgrid::kernel::Future<void> future) {
future.get();
- XBT_INFO("kernelSync with void");
+ XBT_INFO("kernel_sync with void");
});
});
- XBT_INFO("kernelSync with void, returned");
+ XBT_INFO("kernel_sync with void, returned");
// Synchronize on a failing Future<void>:
try {
- simgrid::simix::kernelSync([] {
+ simgrid::simix::kernel_sync([] {
return kernel_wait_until(20).then([](simgrid::kernel::Future<void> future) {
future.get();
throw example::exception("Exception throwed from kernel_defer");
}
// Synchronize on a successul Future<int> and get the value:
- int res = simgrid::simix::kernelSync([] {
+ int res = simgrid::simix::kernel_sync([] {
return kernel_wait_until(30).then([](simgrid::kernel::Future<void> future) {
future.get();
- XBT_INFO("kernelSync with value");
+ XBT_INFO("kernel_sync with value");
return 42;
});
});
- XBT_INFO("kernelSync with value returned with %i", res);
+ XBT_INFO("kernel_sync with value returned with %i", res);
// Synchronize on a successul Future<int> and get the value:
- simgrid::simix::Future<int> future = simgrid::simix::kernelAsync([] {
+ simgrid::simix::Future<int> future = simgrid::simix::kernel_async([] {
return kernel_wait_until(50).then([](simgrid::kernel::Future<void> future) {
future.get();
- XBT_INFO("kernelAsync with value");
+ XBT_INFO("kernel_async with value");
return 43;
});
});
res = future.get();
- XBT_INFO("kernelAsync with value returned with %i", res);
+ XBT_INFO("kernel_async with value returned with %i", res);
// Synchronize on a successul Future<int> and get the value:
- future = simgrid::simix::kernelAsync([] {
+ future = simgrid::simix::kernel_async([] {
return kernel_wait_until(60).then([](simgrid::kernel::Future<void> future) {
future.get();
- XBT_INFO("kernelAsync with value");
+ XBT_INFO("kernel_async with value");
return 43;
});
});
future.wait();
XBT_INFO("The future is %s", future.is_ready() ? "ready" : "not ready");
res = future.get();
- XBT_INFO("kernelAsync with value returned with %i", res);
+ XBT_INFO("kernel_async with value returned with %i", res);
return 0;
}
> [Tremblay:master:(1) 0.000000] [test/INFO] Start
> [0.000000] [test/INFO] kernel
> [Tremblay:master:(1) 0.000000] [test/INFO] kernel, returned
-> [10.000000] [test/INFO] kernelSync with void
-> [Tremblay:master:(1) 10.000000] [test/INFO] kernelSync with void, returned
+> [10.000000] [test/INFO] kernel_sync with void
+> [Tremblay:master:(1) 10.000000] [test/INFO] kernel_sync with void, returned
> [Tremblay:master:(1) 20.000000] [test/INFO] Exception caught: Exception throwed from kernel_defer
-> [30.000000] [test/INFO] kernelSync with value
-> [Tremblay:master:(1) 30.000000] [test/INFO] kernelSync with value returned with 42
-> [50.000000] [test/INFO] kernelAsync with value
-> [Tremblay:master:(1) 50.000000] [test/INFO] kernelAsync with value returned with 43
+> [30.000000] [test/INFO] kernel_sync with value
+> [Tremblay:master:(1) 30.000000] [test/INFO] kernel_sync with value returned with 42
+> [50.000000] [test/INFO] kernel_async with value
+> [Tremblay:master:(1) 50.000000] [test/INFO] kernel_async with value returned with 43
> [Tremblay:master:(1) 50.000000] [test/INFO] The future is not ready
-> [60.000000] [test/INFO] kernelAsync with value
+> [60.000000] [test/INFO] kernel_async with value
> [Tremblay:master:(1) 60.000000] [test/INFO] The future is ready
-> [Tremblay:master:(1) 60.000000] [test/INFO] kernelAsync with value returned with 43
\ No newline at end of file
+> [Tremblay:master:(1) 60.000000] [test/INFO] kernel_async with value returned with 43
\ No newline at end of file