2 unstable releases

0.4.0 May 27, 2021
0.3.0 Nov 16, 2020
0.2.0 Oct 12, 2020
0.1.1 May 27, 2018
0.1.0 May 27, 2018

#85 in Concurrency

Download history 8/week @ 2021-07-02 5/week @ 2021-07-09 13/week @ 2021-07-16 2/week @ 2021-07-23 15/week @ 2021-07-30 13/week @ 2021-08-06 12/week @ 2021-08-13 6/week @ 2021-08-20 8/week @ 2021-08-27 6/week @ 2021-09-03 22/week @ 2021-09-10 4/week @ 2021-09-17 7/week @ 2021-10-01 10/week @ 2021-10-08 159/week @ 2021-10-15

161 downloads per month
Used in 3 crates

MIT license

7KB
104 lines

A simple non-blocking mutex (i.e. only try_lock is supported), using atomics.

Simpler and faster than the one found in stdlib. Does not support poisoning.

Performance

This library has criterion benchmarks. Here is a output from running it on my Ubuntu machine:

build_try               time:   [24.104 us 24.109 us 24.115 us]
Found 9 outliers among 100 measurements (9.00%)
4 (4.00%) high mild
5 (5.00%) high severe

build_std               time:   [2.0887 ms 2.1055 ms 2.1294 ms]
Found 5 outliers among 100 measurements (5.00%)
1 (1.00%) high mild
4 (4.00%) high severe

lock_try                time:   [613.61 us 613.77 us 613.98 us]
Found 9 outliers among 100 measurements (9.00%)
1 (1.00%) low severe
8 (8.00%) high severe

lock_std                time:   [1.5453 ms 1.5459 ms 1.5466 ms]
Found 11 outliers among 100 measurements (11.00%)
4 (4.00%) high mild
7 (7.00%) high severe

contested_try           time:   [1.0300 ms 1.0312 ms 1.0327 ms]
Found 14 outliers among 100 measurements (14.00%)
1 (1.00%) low mild
4 (4.00%) high mild
9 (9.00%) high severe

contested_std           time:   [2.3053 ms 2.3079 ms 2.3110 ms]
Found 19 outliers among 100 measurements (19.00%)
3 (3.00%) high mild
16 (16.00%) high severe

The gist of it is that, compared to std::Mutex, TryMutex is approximately 88 times faster to construct and twice as fast to lock. However, performance on your OS and machine might vary, so be sure to run cargo bench yourself.

No runtime deps