Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

JNA 5.13.0: C++ Side Mutex Creation Fails with "Invalid Memory" Error

未关闭
#1,670 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
cpp, java
领域
tooling

调研方向

首先使用提供的 createMutex 示例复现 Java JNA 对 MSVC 构建的 C++ 库的调用,然后检查 Java/native 边界,以及报告无效内存访问的 mutex 构造或锁定位置。完成的标准是确定无效内存访问的原因,并确认在 Windows 10 上修正后的交互正常。

由索引模型根据 Issue 内容生成。

描述

Description:

When using JNA 5.13.0 to interface with a C++ library, an issue arises where attempting to create a mutex on the C++ side results in an "invalid memory" error. This issue occurs consistently whenever the mutex creation is attempted. Below are the details of the environment and the problem:

Environment:

  • Java Version: 1.8.0_361 (Oracle JDK)
  • JNA Version: 5.13.0(5.17.0 same err)
  • Operating System: [Windows 10]
  • C++ Compiler/Environment: [MSVC]

Problem Description:
The Java application uses JNA to interact with a native C++ library.
On the C++ side, when attempting to create a std::mutex (or any other type of mutex), the program throws an error related to invalid memory access.
The error message or behavior indicates that the memory allocation or usage for the mutex is corrupted or invalid.

Example Code:

Java Side:

public interface MyLibrary extends Library {
    MyLibrary INSTANCE = Native.load("mylibrary", MyLibrary.class);

    void createMutex();
}

public class Main {
    public static void main(String[] args) {
        MyLibrary.INSTANCE.createMutex();
    }
}

C++ Side:

#include <mutex>
extern "C" {
    void createMutex() {
        std::mutex mtx; // Attempting to create a mutex
        mtx.lock();      // Error occurs here or during construction
        mtx.unlock();
    }
}

Error
java.lang.Error: Invalid memory access

主要语言
Java
星标
8.9k
派生
1.7k
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

java-native-access/jna 的其他 Issue

查看 java-native-access/jna 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。