[swift-users] Implicitly capture a mutating self

Zhao Xin owenzx at gmail.com
Fri Dec 16 02:05:26 CST 2016


I did not test the code. But if you cannot implicitly capture a mutating
self, you should do it explicitly, right?

let blockSize = min(512, count)
let blockCount = (count+blockSize-1)/blockSize
device.sync { *[self] () -> () in* // Launch CUDA kernel
    try! fill<<<(blockSize, blockCount)>>>[
        .pointer(to: &self), .value(value), .value(Int64(count))
    ]
}

Hope above code works.

Zhaoxin

On Fri, Dec 16, 2016 at 3:46 PM, Richard Wei via swift-users <
swift-users at swift.org> wrote:

> Hi,
>
> Swift 3.0.2 seems to have broken my code due to mutating self capture. But
> I have to pass inout self to the closure. Any workaround?
>
>     let blockSize = min(512, count)
>     let blockCount = (count+blockSize-1)/blockSize
>     device.sync { // Launch CUDA kernel
>         try! fill<<<(blockSize, blockCount)>>>[
>             .pointer(to: &self), .value(value), .value(Int64(count))
>         ]
>     }
>
>
> -Richard
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161216/9f6ce79e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-1.png
Type: image/png
Size: 7055 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161216/9f6ce79e/attachment.png>


More information about the swift-users mailing list