Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: slice append lose the data for NSScanner #19373

Merged
merged 2 commits into from Mar 28, 2024

Conversation

jiuker
Copy link
Contributor

@jiuker jiuker commented Mar 28, 2024

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers
under the terms of the Apache 2 license.
By creating this pull request I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 license.

Description

fix: slice append lose the data

package main

import (
	"fmt"
	"sync"
)

func main() {
	for j := 0; j < 10; j++ {
		s := []string{}
		wg := sync.WaitGroup{}
		mu := sync.Mutex{}
		for i := 0; i < 50; i++ {
			wg.Add(1)
			s = append(s, "")
			go func(i int) {
				defer wg.Done()
				mu.Lock()
				s[i] = fmt.Sprintf("%d", i)
				mu.Unlock()
			}(len(s) - 1)
		}
		wg.Wait()
		if index, ok := check(s); ok {
			fmt.Println(s, index)
		}
	}
}

func check(datas []string) (int, bool) {
	for index, data := range datas {
		if data == "" {
			return index, true
		}
	}
	return 0, false
}

will show some slice will lose the data.

[0  2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49] 1

Motivation and Context

How to test this PR?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Optimization (provides speedup with no functional changes)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • Fixes a regression (If yes, please add commit-id or PR # here)
  • Unit tests added/updated
  • Internal documentation updated
  • Create a documentation update request here

fix: slice append lose the data
Copy link
Member

@vadmeste vadmeste left a comment

Choose a reason for hiding this comment

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

LGTM

@harshavardhana harshavardhana merged commit 8222a64 into minio:master Mar 28, 2024
20 checks passed
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.

None yet

4 participants