在 Windows 上使用 Mingw 使用 pthread 时出错 [英] Error using pthread on Windows with Mingw

查看:80
本文介绍了在 Windows 上使用 Mingw 使用 pthread 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows C 程序上使用线程,在 Eclipse 环境和 Mingw 上编译.

I'm trying to use threads on a Windows C program, compiled on an Eclipse environment and Mingw.

我还在编译命令中添加了 -lpthread 和 -pthread,并包含在程序中.

I've also put -lpthread and -pthread on the compilation command, and included on the program.

我根据我的逻辑在适当的地方调用了 pthread_create()、pthread_cancel() 和 pthread_exit().

I made calls to pthread_create(), pthread_cancel() and pthread_exit() where appropriate on my logic.

它总是按预期工作,但我的程序结束说

It always works as intended, but that my program ends saying

此应用程序已请求运行时终止它不寻常的方式.请联系应用程序的支持团队了解更多信息.

This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

有什么提示吗?我错过了什么吗?

Any hints? Am I missing something?

更新

全局变量:

pthread_t thr;

启动函数内部:

pthread_create(&thr,NULL,ThrFunc,NULL);
pthread_join(thr,NULL);

ThrFunc 内部:

while (TRUE)
{
    // do something
    if (some other thing occurs)
       pthread_exit();
}

推荐答案

已解决!

AFAIK 在 Mingw 下没有适用于 Windows 的可移植 pthread 库.

AFAIK there is no portable pthread library for Windows under Mingw.

我使用 CreateThread() 解决了我的问题,并让 Mingw 使用 Windows 本地线程来解决它.

I solved my problem using CreateThread(), and let Mingw resolves it using Windows native threads.

这篇关于在 Windows 上使用 Mingw 使用 pthread 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆