V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  YanSeven  ›  全部回复第 5 页 / 共 24 页
回复总数  462
1  2  3  4  5  6  7  8  9  10 ... 24  
这个就如同完全让”智驾”在路上狂飙一样让人心惊胆战。
44 天前
回复了 YanSeven 创建的主题 Go 编程语言 go 最新版的 map 并发读是安全的吗。
Maps are not safe for concurrent use: it’s not defined what happens when you read and write to them simultaneously. If you need to read from and write to a map from concurrently executing goroutines, the accesses must be mediated by some kind of synchronization mechanism. One common way to protect maps is with sync.RWMutex.
映射结构不适用于并发场景:当同时进行读写操作时,其行为是未定义的。若需要在并发执行的 goroutine 中对映射进行读写操作,必须通过某种同步机制来协调访问。保护映射的常用方式之一是使用 sync.RWMutex 。

This statement declares a counter variable that is an anonymous struct containing a map and an embedded sync.RWMutex.
该语句声明了一个 counter 变量,这是一个包含映射和嵌入式 sync.RWMutex 的匿名结构体。

var counter = struct{
sync.RWMutex
m map[string]int
}{m: make(map[string]int)}
To read from the counter, take the read lock:
读取计数器时需获取读锁:

counter.RLock()
n := counter.m["some_key"]
counter.RUnlock()
fmt.Println("some_key:", n)
To write to the counter, take the write lock:
写入计数器时需获取写锁:

counter.Lock()
counter.m["some_key"]++
counter.Unlock()

来源: https://go.dev/blog/maps?utm_source=chatgpt.com
@viking602 goland 有啥体验是 vscode 无法提供的吗,目前我 go 开发几乎都是 vscode 了,goland 尝试了几次,没用下去
@looplj WindSurf 的 Teams 里面最多能加几个人。
补上一个 Trae
45 天前
回复了 charoneo 创建的主题 程序员 写代码用 claude code 还是 codex?
claude code 用不到,疯狂封,只能 codex
原文档内容:The zero Map is empty and ready for use. A Map must not be copied after first use.

Map 的定义如下:
```
type Map struct {
_ noCopy // 这个在源码中设置

m isync.HashTrieMap[any, any]
}
```

noCopy 类型的说明:
noCopy may be added to structs which must not be copied
after the first use.

See https://golang.org/issues/8005#issuecomment-190753527
for details.

Note that it must not be embedded, due to the Lock and Unlock methods.

如果你想问,进一步为什么 Map 是“noCopy"的,需要进一步研究 HashTrieMap 的结构:

```go
type HashTrieMap[K comparable, V any] struct {
inited atomic.Uint32
initMu Mutex
root atomic.Pointer[indirect[K, V]]
keyHash hashFunc
valEqual equalFunc
seed uintptr
}
```
可以看到里面封装了 Mutex ,先不管其他变量,至少 Mutex 是肯定不可拷贝的, 内部维护锁的状态( locked/unlocked )以及等待队列这些资源。
GLM 肯定是比不上 Codex 。但是胜在省钱。
@juggtt213 没错,你说的这个场景正是我问问题时的场景。
MacOS+虚拟机,或许在续航上仍能一战。Mac 开发涉及到编译也很难和纯 Linux 一样,得操心一下一些底层的框架和库,毕竟和跑程序的主流的硬件架构以及 OS 都不一样。
@momocraft 感谢
所以说,所有的智能都得是辅助智能,全自动不存在的。让 AI 辅助的领域一定得是开发者能驾驭的领域。信马由缰大概率翻车摔沟里。出了 bug 用户不知道,开发者不会调,这个对软件来说是灾难。
如果另一个项目是你做的,那你这个不好说。如果是别人做的,你只是提了一嘴,那这个作者这个不好说
@isno 佬,我 23 年就看过你写的这个书,新版是不是相对于旧版删减了东西
48 天前
回复了 unbinilium 创建的主题 程序员 记因 API 第一次挨同事骂
朋友来了有酒肉,敌人来了有猎枪。
@ThomasKim 即苹果用户对“情绪价值”的需求高于“功能性”,这个感觉对做领域内的“奢侈品”是个不容忽视的需求。
50 天前
回复了 xiguadong 创建的主题 程序员 zed 有点厉害
所以 zed 的功能区能调吗,左下角好不习惯啊
你的程序本身是不是有问题,运行时间一长造成资源泄露,甚至日志一直打把卷的空间都堆到头了,自然就无法处理请求了。
云环境本身的网络问题可能性不太大。
硬盘准备怎么买,最近的固态和机械都是狂涨。一直舍不得买硬盘。
这个感觉更像是“传播”和“营销”上的事情。GNU/Linux 无论是正式场合还是非正式,说起来都太拗口了。除非是特别的专门场合。

至于“营销”,行内人知道 Linux 的没有不知道 GNU 的,这是课本上的东西。

行外人知道 Linux 的顶多知道它是一个操作系统。人们不是认识了 Linux ,而是认识了是一个新操作系统。因为操作系统每个人都在接触,所以 Linux 作为操作系统的概念在行外人的认知里面就广泛了一点。
1  2  3  4  5  6  7  8  9  10 ... 24  
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1005 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 44ms · UTC 23:55 · PVG 07:55 · LAX 15:55 · JFK 18:55
♥ Do have faith in what you're doing.