【问题标题】:calling Napi::ThreadSafeFunction::Release() results in ELIFECYCLE 3221225477 (STATUS_ACCESS_VIOLATION)调用 Napi::ThreadSafeFunction::Release() 导致 ELIFECYCLE 3221225477 (STATUS_ACCESS_VIOLATION)
【发布时间】:2020-02-04 11:46:39
【问题描述】:

标题中提到我有一些奇怪的线程问题。

基本上,我将PS2000 Api 与node-addon-api 包装起来,就像链接示例中一样。

由于这些 api 回调需要类似“C”的函数,所以我用类似这样的东西来实现它们:

CLASSNAME *trampoline[N] = {}
template<int I>f(...){
  trampoline[I]->tsfn.BlockingCall(&args, [](..., *args){
     //do stuff
     if(trampoline->calledCallbacksCount >= trampoline->estimatedCallbackCount){
            trampoline->tsfn.Release();
     }
  })
}
CALLBACK *fptr[N] = {
   f<0>, ..., f<N>
}

CLASSNAME::CLASSNAME(){
   trampoline[nextEmptyIndex] = this;
   this->callback = fptr[nextEmtyIndex];
}
CLASSNAME::read(){
   this->tsfn = Napi::ThreadSafeFunction::New(...)
   //...
   nativethread = std::thread([this]{
       //... start device stream & wait some time
       if(ps2000_get_streaming_last_values(this->deviceHandle, this->callback) == 0){
          // no callback
       }
       if(this->calledCallbacksCount >= this->estimatedCallbackCount){
            this->tsfn.Release();
       }
   }
}

void my_get_overview_buffers

(
   short **overviewBuffers,
   short overflow,
   unsigned long triggeredAt,
   short triggered,
   short auto_stop,
   unsigned long nValues
)

api函数ps2000_get_streaming_last_values可以多次调用回调,回调次数可以通过**overviewBuffers(nValues)的长度来估算。

当我省略 tsfn.Release() 时,没有错误。

使用时也会返回napi_ok。

感觉好像有某种迟到的回调到空虚 - 但只有当线程被释放时......

我不知所措 - 有人有想法吗?


等等!

传递到 jsCallback.Call({Napi::ArrayBuffer::New(env, *buffer, size)}) 的 memcpied *buffers 会发生什么

这是访问冲突吗?在不发布 tsfn 的情况下如何解决这个问题?


我正在使用 VSCODE 开发 Windows,

我的启动 json 包含:

     {
        "name": "Debug",
        "type": "cppvsdbg",
        "request": "launch",
        "program": "node",
        "args": ["index.ts"],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false
    }

但调试器没有触发...

【问题讨论】:

    标签: c++ node.js node-addon-api


    【解决方案1】:

    该问题不与 node-addon-api 相关。

    这是由于 picoscope 设备由于延迟而收集大量数据而导致的缓冲区溢出,或者最终导致 nValues &gt; OverviewBufferSize 在复制这些缓冲区时导致超出范围的访问,从而导致访问违规。

    只需处理这些情况并扩大缓冲区大小即可解决此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-02
      • 2021-04-13
      • 2020-09-17
      • 2016-05-22
      • 2018-03-28
      • 1970-01-01
      • 1970-01-01
      • 2021-06-18
      相关资源
      最近更新 更多