inh3 / nPool

A cross-platform thread pool add-on for Node.js and io.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to install on Windows - error C2440: 'function' : cannot convert from 'THREAD_FUNC (__cdecl *)(void *)' to 'unsigned int (__stdcall *)(void *)'

naderchehab opened this issue · comments

I get the following error when trying to install on Windows 8. Any suggestions appreciated!

E:\myproject>npm install npool
npm WARN package.json myproject@0.0.1 No repository field.
npm http GET https://registry.npmjs.org/npool
npm http 304 https://registry.npmjs.org/npool

> npool@1.1.0 install E:\myproject\node_modules\npool
> node-gyp rebuild


E:\myproject\node_modules\npool>node "E:\Program Files (x86)\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  thread_pool.c
  task_queue.c
  synchronize.c
..\threadpool\synchronize.c(65): error C2440: 'function' : cannot convert from 'THREAD_FUNC (__cdecl *)(void *)' to 'unsigned int (__stdcall *)(void *)' 
[E:\myproject\node_modules\npool\build\threadpool.vcxproj]
..\threadpool\synchronize.c(65): warning C4024: '_beginthreadex' : different types for formal and actual parameter 3 [E:\myproject\node_modules\npool\build\threadpool.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (E:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Windows_NT 6.2.9200
gyp ERR! command "node" "E:\\Program Files (x86)\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd E:\myproject\node_modules\npool
gyp ERR! node -v v0.10.21
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0

E:\myproject>

Fixed the issue, sorry about that. Was missing the necessary __stdcall for the Windows thread function.

Already published to npm version 1.1.1 with the fix. Let me know if that works out.

Left one file out getting that committed now.

File is committed and published npool 1.1.2 to npm.

I'll close once you let me know your build is okay.

The build is ok, thank you! However once I run a basic example such as this, I get the following error:

"E:\Program Files (x86)\nodejs\node.exe" npool-test.js
Process finished with exit code -1073741819

Glad the build worked out!

unitOfWork.fileKey = 2;

This line should be:

unitOfWork.fileKey = 1;

This is because you are loading the file at index one here:

// load files defining object types
nPool.loadFile(1, __dirname + '/helloWorld.js');
  • fileKey uint32 - This parameter is an integer that is used as a key to reference a file that was previously cached via the loadFile function. At this time there is no run-time logic to handle the a case when a file key does not reference a previously loaded file. Therefore, ensure that a file exists for the given key.

One more thing to note, if you want your program to terminate, you will need to destroy the thread pool at some point. The thread pool keeps the run script "alive" due to the background threads unless you destroy it explicitly.

So, add something like this to the end of your script.

// let the thread pool get to the work, then
// eventually get rid of the thread pool
setTimeout(function() {
    nPool.destroyThreadPool();
}, 500);

D'oh - my bad. I will try this as soon as I get home! Thank you for your extremely speedy and thorough replies!