0

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();
}
Mohan
  • 1,871
  • 21
  • 34
Nilo Paim
  • 428
  • 6
  • 22
  • 1
    Impossible to tell without seeing the code. – nos Nov 23 '15 at 17:29
  • Maybe you're releasing the resources of the pthread before it returns from its start function? – Neijwiert Nov 23 '15 at 17:35
  • "*calls to `pthread_cancel()`*" make me feel uncomfortable ... – alk Nov 23 '15 at 17:36
  • Whatever you have shown so far looks fine. What's that *start* function? Is it the main() function of your application? Can you include an [mcve](http://stackoverflow.com/help/mcve)? – P.P Nov 23 '15 at 18:15
  • @BlueMoon In fact, this code is contained on a DLL. The start function is a function exported from this DLL and called by the main() function of the application. – Nilo Paim Nov 23 '15 at 18:32
  • That's fine. But my previous comments' questions still stand. It's not possible to tell *why* you get that message with whatever you have shown so far. – P.P Nov 23 '15 at 18:40
  • No way to get a quick mcve. It's interesting that commenting all pthread commands on the source and compiling, the program obviously does not do what I want, but the error message remains. It only dissapears when I also take off -lpthread from the compiling command. – Nilo Paim Nov 23 '15 at 19:00
  • 1
    Does this answer your question? [How to run pthreads on windows](https://stackoverflow.com/questions/7542286/how-to-run-pthreads-on-windows) – Henke Nov 29 '20 at 14:25

2 Answers2

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 .

Mohan
  • 1,871
  • 21
  • 34
0

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.

Nilo Paim
  • 428
  • 6
  • 22