Error using pthread on Windows with Mingw

◇◆丶佛笑我妖孽 提交于 2020-12-27 06:08:51

问题


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

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

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?

Update

Global variable:

pthread_t thr;

Inside the start function:

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

Inside ThrFunc:

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

回答1:


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

To solve this have look on this.

Or

When abort() function is getting called from your application you will see that error.

From MSDN:

abort

Aborts the current process and returns an error code.

void abort( void ); Return Value

abort does not return control to the calling process. By default, it terminates the current process and returns an exit code of 3.

Remarks

By default, the abort routine prints the message:

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

But in your case you need to find why abort() is getting called .




回答2:


Solved!

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

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



来源:https://stackoverflow.com/questions/33876991/error-using-pthread-on-windows-with-mingw

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!