Skip to content

Conversation

@MinyazevR
Copy link
Owner

No description provided.

/// <inheritdoc/>
public override T Get()
{
///if the value has already been calculated, there should be no locks

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут обычный комментарий, не XMLDoc, так что

Suggested change
///if the value has already been calculated, there should be no locks
// if the value has already been calculated, there should be no locks

if (!Volatile.Read(ref isAlreadyCounted))
{
value = func();
isAlreadyCounted = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо ещё func занулить, чтобы сборщик мусора мог её собрать

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А isAlreadyCounted = true бесполезно, потому что строчкой ниже мы делаем то же самое, только лучше

}
}

return value!;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А вот плохо null-forgiving operator. Либо честно кидайте исключение, если null, либо официально разрешите значению быть null (в условии это вроде предполагалось)

{
static int Increment(int number) => number + 1;
Lazy.ILazy<int> lazy = new Lazy.MultithreadedLazy<int>(() => Increment(0));
Thread[] threads = new Thread[8];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var

[Test]
public void ShouldValueNotChangeForLazyInMultithreadedMode()
{
static int Increment(int number) => number + 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Непоказательно. Из-за гонки по + 1 может получиться, что там все Lazy вызвались и посчитались, а ответ всё равно 1

Comment on lines 39 to 41
threads[i] = new Thread(() => {
Assert.That(lazy.Get(), Is.EqualTo(1));
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Фигурные скобки лишние

Copy link

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants