Skip to content

Создала pull request HW7#7

Open
Nigma-Ks wants to merge 6 commits intomainfrom
HW7
Open

Создала pull request HW7#7
Nigma-Ks wants to merge 6 commits intomainfrom
HW7

Conversation

@Nigma-Ks
Copy link
Copy Markdown
Owner

No description provided.

module Program =

[<EntryPoint>]
let main _ = 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Это не нужно


isEqual

Check.Quick multiThreadLazyChecker
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Надо Check.QuickThrowOnFailure

Lazy/Lazy.fs Outdated
finally
Monitor.Exit(lockObj)

type FreeLockLazy<'a>(supplier: unit -> 'a) =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Оно "LockFree" по идее.

for result in results do
isEqual <- (result = results.[0]) && isEqual

isEqual
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

А как это доказывает, что supplier вызвался один раз? supplier на все десять прогонов один, возвращает int, так что может вызваться хоть 10 раз, он просто одно и то же число вернёт.


open System.Threading

module Lazy =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Тут тоже надо комментарии

Lazy/Lazy.fs Outdated
value.Value
| Some x -> x
finally
Monitor.Exit(lockObj)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Есть библиотечная функция lock, которая делает то же самое. Правильнее её использовать.

Lazy/Lazy.fs Outdated

interface ILazy<'a> with
member this.Get() =
Monitor.Enter(lockObj)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Если брать замок на каждый вызов Get, от такой реализации в многопоточном сценарии никакого толка не будет, потому что все потоки будут обязаны синхронизироваться на Get всегда, тогда как гонка может быть только пока Lazy не инициализирован.


let multiThreadLazy =
newILazy (fun () ->
count <- count + 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interlocked.Increment. Иначе даже если supplier вызывается много раз, из-за гонки при сложении это может быть не видно.

Lazy/Lazy.fs Outdated
interface ILazy<'a> with
/// <inheritdoc/>
member this.Get() =
lock (lockObj) (fun () ->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Тут основное замечание было в том, что это избыточный lock, не поправлено

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.

2 participants