Compiling crafty: _beginthreadex()

Discussion of chess software programming and technical issues.

Moderator: Ras

Cardoso
Posts: 363
Joined: Thu Mar 16, 2006 7:39 pm
Location: Portugal
Full name: Alvaro Cardoso

Compiling crafty: _beginthreadex()

Post by Cardoso »

Hi,
I'm using Visual Studio c++ 2008.
since _beginthreadex() gives a compiling error:
error C2664: '_beginthreadex' : cannot convert parameter 3 from 'void *' to 'unsigned int (__stdcall *)(void *)'

I search this forum and Lance Perkins gave the following tip:
. Replace _beginthreadex with CreateThread, and cast the parameter "func" with "(PTHREAD_START_ROUTINE)func".

So my question is it safe to replace:

Code: Select all

hThread = (HANDLE) _beginthreadex(0, 0, func, args, 0, 0);
with:

Code: Select all

hThread = (HANDLE) CreateThread(0, 0, (PTHREAD_START_ROUTINE)func, args, 0, 0);
does crafty's thread terminate functions work properly with CreateThread() ?
BTW I did not try this.

thanks in advance,
Alvaro
trojanfoe

Re: Compiling crafty: _beginthreadex()

Post by trojanfoe »

No it's not safe to replace _beginthreadex() with CreateThread() as the _beginthread() functions are used to initialise the thread-local elements of the Microsoft C Runtime library which CreateThread doesn't do.

It looks to me like you are passing in something other than a pointer to your thread entry function given the compiler thinks it's void *. I would also use _beginthread() unless you are actually going to use the additional options that _beginthreadex() give you.

Cheers,
Andy
jhaglund
Posts: 173
Joined: Sun May 11, 2008 7:43 am

Re: Compiling crafty: _beginthreadex()

Post by jhaglund »

Lance was replying to me on how to compile Crafty with the Borland compiler if you read the _thread. ;)