Capturing makes it immutable, which unfortunately can't solve this problem.
-Richard > On Dec 16, 2016, at 02:05, Zhao Xin <owe...@gmail.com> wrote: > > 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@swift.org <mailto:swift-users@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)) > ] > } > > <PastedGraphic-1.png> > > -Richard > > _______________________________________________ > swift-users mailing list > swift-users@swift.org <mailto:swift-users@swift.org> > https://lists.swift.org/mailman/listinfo/swift-users > <https://lists.swift.org/mailman/listinfo/swift-users> > >
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users