CUDA By Example Questions Questions or troubles regarding examples in the book CUDA By Example.

arg. I hope the error message is enough. But probably not.

In the book, section 11.3, the example code fails to compile.

Basically, I don’t understand why the given definition for CUT_THREADROUTINE didn’t work.

#include <windows.h>

typedef HANDLE CUTThread;

//typedef unsigned (WINAPI *CUT_THREADROUTINE)(void *);   // causes quoted error

//typedef void *(WINAPI *CUT_THREADROUTINE)(void *);      // causes quoted error 

typedef void *(*CUT_THREADROUTINE)(void *);               // compiles

#define CUT_THREADPROC unsigned WINAPI

#define  CUT_THREADEND return 0

//Create thread

CUTThread start_thread( CUT_THREADROUTINE func, void *data ) {

	return CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, data, 0, NULL);


You can’t mess with calling convention like that! Create Thread expects WINAPI calling convention, passing anything else (which is __cdecl by default) will corrupt the stack. There is probably a simple to fix mistake in that code, but I can’t help you without seeing it.

I’m also interested in finding out how to solve this problem.

Send me the code, then I’d have a look.

We were able to fix this by changing the definition of the function “routine”

  • from: void* routine( void *pvoidData ) { … }
  • to: unsigned WINAPI routine( void *pvoidData ) {…}
1 Like

This worked for me, thanks!