【问题标题】:pthread_mutex_t {aka union <anonymous>}’ has no member named ‘abi’pthread_mutex_t {aka union <anonymous>}' 没有名为“abi”的成员
【发布时间】:2022-06-30 19:05:16
【问题描述】:

我一直在尝试编写一个基于称为POOL 的可锁定队列(在本例中为seq)的数据库连接池。我想将POOL 作为全局变量,然后使用initConnectionPool 对其进行实例化。我尝试使用下面的代码这样做

var POOL: ConnectionPool

proc initConnectionPool*(initialPoolSize: static int) = 
  POOL = ConnectionPool(connections: @[])
  initLock(POOL.lock)

但是,这会引发编译器错误:

‘pthread_mutex_t {aka union <anonymous>}’ has no member named ‘abi’

我不太确定这应该是什么意思或如何处理。我该如何解决这个问题?

【问题讨论】:

  • 幸运的是,我无法在 macOS 上使用 nim v1.6.2 重现这一点。
  • @hola 好点。以上来自 Ubuntu 18.04.6 LTS 上的 nim v1.6.2(git hash as per nim -v: 9084d9bc02bcd983b81a4c76a05f27b9ce2707dd)

标签: locking nim-lang


【解决方案1】:

更新:从 nim v. 1.6.6 开始,这似乎不再是问题并且可以完美运行。

对于 pre nim v.1.6.6:

这似乎是known issue。谢天谢地,xflywind 帮我指出了正确的答案。

POOL = ConnectionPool(connections: @[]) 在 proc 中是不允许的,这会导致编译问题。您应该在这里做的是,而不是实例化此对象,而是在此处分配各个字段,就好像该对象已经存在一样,因为在某种程度上,它已经存在了。

所以这将编译:

proc initConnectionPool*(initialPoolSize: static int) = 
  POOL.connections: @[]
  initLock(POOL.lock)

【讨论】:

    猜你喜欢
    • 2014-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    • 2014-11-09
    相关资源
    最近更新 更多