         }
 
         public func decode(_ data: Data) throws -> ImageContainer {
+            lock.lock()
+            defer { lock.unlock() }
+
             func makeImage() -> PlatformImage? {
                 if let thumbnail = self.thumbnail {
                     return makeThumbnail(data: data, options: thumbnail)

   return false
}

private struct ProgressiveJPEGScanner {
    // Number of scans that the decoder has found so far. The last scan might be
    // incomplete at this point.
    private(set) var numberOfScans = 0

    ///
    /// - note: The default decoder supports progressive JPEG. It produces a new
    /// preview every time it encounters a new full frame.
    public final class Default: ImageDecoding, @unchecked Sendable {
        // Number of scans that the decoder has found so far. The last scan might be
        // incomplete at this point.
        var numberOfScans: Int { scanner.numberOfScans }
