[synchronized]
(Simple and convenient macro for synchronizing code in multithreading. )
Usage
Add this to your Cargo.toml:
[]
= "1.1.0"
and this to your source code:
use sync;
Example
1. sync_static
use spawn;
use sync;
/*
A more illustrative example of code blocking implementation
for SAFE mutability of two or more static variables.
The code creates 5 threads that try to change static variables at the same
time without synchronization, but the code synchronization block
does not allow this code to execute at the same time, which makes
the implementation of changing static variables SAFE and even somewhat
easier and more beneficial in terms of use and performance.
*/
2. point
/*
An example implementation of synchronized code with
one non-anonymous synchronization point.
This example creates a set of anonymous sync codes associated with a
single named sync point. Each synchronization code executes in the same
way as ordinary anonymous code, but execution occurs simultaneously in a
multi-threaded environment in only one of them.
!!! In this example, the assembly requires the `point` feature to be active.
*/
use sync_point;
use sync;
3. sync_let
use spawn;
use sync;
/*
An example that describes how to quickly create an anonymous
sync with a mutable variable.
This code creates 5 threads, each of which tries to update
the `sync_let` variable with data while executing the synchronized anonymous code.
*/
Features
Synchronized supports locks from the standard std
package, as well as the parking_lot
package, and also supports asynchronous operation using locks from tokio
:
1. std
(only synchronization locks from the std
library)
= "1.1.0"
default-features = false
features =
version
2. parking_lot
(only synchronization locks from the parking_lot
library)
= "1.1.0"
default-features = false
features =
version
3. tokio
(only async locks from tokio
library)
= "1.1.0"
default-features = false
features =
version
License
This project is distributed under the license (LICENSE-APACHE-2-0).
(Denis Kotlyarov).