Coder Social home page Coder Social logo

node-threads-a-gogo's Introduction

build status npm version


TAGG: Threads à gogo for Node.js

Threads à gogo (*) is a native module for Node.js that provides an asynchronous, evented and/or continuation passing style API for moving blocking/longish CPU-bound tasks out of Node's event loop to JavaScript threads that run in parallel in the background and that use all the available CPU cores automatically; all from within a single Node process.

Installing the module

With npm:

npm install threads_a_gogo

From source:

git clone http://github.com/xk/node-threads-a-gogo.git
cd node-threads-a-gogo
# One of
node-gyp rebuild
node test/all.js
# or
npm install
node test/all.js
# or
node-waf configure build install test
# Depending of what wersion of node you've got.
#
# THREADS_A_GOGO CURRENTLY (v0.1.13 / 2017)
# RUNS ON NODES v0.5.1 TO v6.9.2

Basic functionality test:

cd node-threads-a-gogo
node test/all.js
# If all goes well should output something like this:
0.OK.1.OK.2.OK.3.TAGG OBJECT OK
4.OK.5.OK.6.OK.7.OK.8.OK.9.OK.10.OK.11.OK.12.THREAD OBJECT OK
13.OK.WAITING FOR LOAD CB
14.OK.15.LOAD CALLBACK OK
16.OK.WAITING FOR EVAL CB
17.OK.18.OK.19.EVAL CALLBACK OK
20.OK.WAITING FOR EVENT LISTENER CB
21.OK.22.OK.23.OK.24.OK.25.OK.26.EVENT LISTENER CB.OK
27.OK.WAITING FOR DESTROY CB
28.OK.29.DESTROY CB OK
END
THREADS_A_GOGO v0.1.13 BASIC FUNCTIONALITY TEST: OK, IT WORKS!

To include the module in your project:

var tagg= require('threads_a_gogo');

You need a node with a v8 >= 3.2.4 to run this module. Any node >= 0.5.1 comes with a v8 >= 3.2.4.

The module runs fine, though, in any node >= 0.1.13 as long as you build it with a v8 >= 3.2.4, see here. To do that you simply have to replace /node/deps/v8 with a newer version of v8 and recompile it (recompile node). To get any version of node goto http://nodejs.org/dist/, and for v8 goto http://github.com/v8/v8, click on "branch", select the proper tag (>= 3.2.4), and download the .zip.

Intro

After the initialization phase of a Node program, whose purpose is to setup listeners and callbacks to be executed in response to events, the next phase, the proper execution of the program, is orchestrated by the event loop whose duty is to juggle events, listeners and callbacks quickly and without any hiccups nor interruptions that would ruin its performance

Both the event loop and said listeners and callbacks run sequentially in a single thread of execution, Node's main thread. If any of them ever blocks, nothing else will happen for the duration of the block: no more events will be handled, no more callbacks nor listeners nor timeouts nor nextTick()ed functions will have the chance to run and do their job, because they won't be called by the blocked event loop, and the program will turn sluggish at best, or appear to be frozen and dead at worst.

A.- Here's a program that makes Node's event loop spin freely and as fast as possible: it simply prints a dot to the console in each turn:

cat examples/quickIntro_loop.js
node examples/quickIntro_loop.js
(function spinForever () {
  process.stdout.write(".");
  setImmediate(spinForever);
})();

B.- Here's another program that adds to the one above a fibonacci(35) call in each turn, a CPU-bound task that takes quite a while to complete and that blocks the event loop making it spin slowly and clumsily. The point is simply to show that you can't put a job like that in the event loop because Node will stop performing properly when its event loop can't spin fast and freely due to a callback/listener/nextTick()ed function that's blocking.

cat examples/quickIntro_blocking.js
node examples/quickIntro_blocking.js
function fibo (n) {
  return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
}

(function fiboLoop () {
  process.stdout.write(fibo(35).toString());
  setImmediate(fiboLoop);
})();

(function spinForever () {
  process.stdout.write(".");
  setImmediate(spinForever);
})();

C.- The program below uses threads_a_gogo to run the fibonacci(35) calls in a background thread, so Node's event loop isn't blocked at all and can spin freely again at full speed:

cat examples/quickIntro_oneThread.js
node examples/quickIntro_oneThread.js
function fibo (n) {
  return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
}

function cb (err, data) {
  process.stdout.write(data);
  this.eval('fibo(35)', cb);
}

var thread= require('threads_a_gogo').create();

thread.eval(fibo).eval('fibo(35)', cb);

(function spinForever () {
  process.stdout.write(".");
  setImmediate(spinForever);
})();

D.- This example is almost identical to the one above, only that it creates 5 threads instead of one, each running a fibonacci(35) in parallel and in parallel too with Node's event loop that keeps spinning happily at full speed in its own thread:

cat examples/quickIntro_fiveThreads.js
node examples/quickIntro_fiveThreads.js
function fibo (n) {
  return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
}

function cb (err, data) {
  process.stdout.write(" ["+ this.id+ "]"+ data);
  this.eval('fibo(35)', cb);
}

var tagg= require('threads_a_gogo');

tagg.create().eval(fibo).eval('fibo(35)', cb);
tagg.create().eval(fibo).eval('fibo(35)', cb);
tagg.create().eval(fibo).eval('fibo(35)', cb);
tagg.create().eval(fibo).eval('fibo(35)', cb);
tagg.create().eval(fibo).eval('fibo(35)', cb);

(function spinForever () {
  process.stdout.write(".");
  setImmediate(spinForever);
})();

E.- The next one asks threads_a_gogo to create a pool of 10 background threads, instead of creating them manually one by one:

cat examples/quickIntro_multiThread.js
node examples/quickIntro_multiThread.js
function fibo (n) {
  return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
}

var numThreads= 10;
var threadPool= require('threads_a_gogo').createPool(numThreads).all.eval(fibo);

threadPool.all.eval('fibo(35)', function cb (err, data) {
  process.stdout.write(" ["+ this.id+ "]"+ data);
  this.eval('fibo(35)', cb);
});

(function spinForever () {
  process.stdout.write(".");
  setImmediate(spinForever);
})();

F.- This is a demo of the threads_a_gogo eventEmitter API, using one thread:

cat examples/quickIntro_oneThreadEvented.js
node examples/quickIntro_oneThreadEvented.js
var thread= require('threads_a_gogo').create();
thread.load(__dirname + '/quickIntro_evented_childThreadCode.js');

/*
  This is the code that's .load()ed into the child/background thread:
  
  function fibo (n) {
    return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
  }

  thread.on('giveMeTheFibo', function onGiveMeTheFibo (data) {
    this.emit('theFiboIs', fibo(+data)); //Emits 'theFiboIs' in the parent/main thread.
  });
  
*/

//Emit 'giveMeTheFibo' in the child/background thread.
thread.emit('giveMeTheFibo', 35);

//Listener for the 'theFiboIs' events emitted by the child/background thread.
thread.on('theFiboIs', function cb (data) {
  process.stdout.write(data);
  this.emit('giveMeTheFibo', 35);
});

(function spinForever () {
  process.stdout.write(".");
  setImmediate(spinForever);
})();

G.- This is a demo of the threads_a_gogo eventEmitter API, using a pool of threads:

cat examples/quickIntro_multiThreadEvented.js
node examples/quickIntro_multiThreadEvented.js
var numThreads= 10;
var threadPool= require('threads_a_gogo').createPool(numThreads);
threadPool.load(__dirname + '/quickIntro_evented_childThreadCode.js');

/*
  This is the code that's .load()ed into the child/background threads:
  
  function fibo (n) {
    return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
  }

  thread.on('giveMeTheFibo', function onGiveMeTheFibo (data) {
    this.emit('theFiboIs', fibo(+data)); //Emits 'theFiboIs' in the parent/main thread.
  });
  
*/

//Emit 'giveMeTheFibo' in all the child/background threads.
threadPool.all.emit('giveMeTheFibo', 35);

//Listener for the 'theFiboIs' events emitted by the child/background threads.
threadPool.on('theFiboIs', function cb (data) {
  process.stdout.write(" ["+ this.id+ "]"+ data);
  this.emit('giveMeTheFibo', 35);
});

(function spinForever () {
  process.stdout.write(".");
  setImmediate(spinForever);
})();

More examples

The examples directory contains a few more examples:

  • ex01_basic: Running a simple function in a thread.
  • ex02_events: Sending events from a worker thread.
  • ex03_ping_pong: Sending events both ways between the main thread and a worker thread.
  • ex04_main: Loading the worker code from a file.
  • ex05_pool: Using the thread pool.
  • ex06_jason: Passing complex objects to threads.

Module API

TAGG Object API

tagg= require('threads_a_gogo') -> tagg object

{ create: [Function],
  createPool: [Function: createPool],
  version: '0.1.13' }
  

.create()

tagg.create( /* no arguments */ ) -> thread object

.createPool( numThreads )

tagg.createPool( numberOfThreads ) -> threadPool object

.version

tagg.version -> A string with the threads_a_gogo version number.


Thread Object API (this is the thread object you get in node's main thread)

thread= tagg.create() -> thread object

{ load: [Function: load],
  eval: [Function: eval],
  emit: [Function: emit],
  destroy: [Function: destroy],
  id: 0,
  version: '0.1.13',
  on: [Function: on],
  once: [Function: once],
  _on: {},
  removeAllListeners: [Function: removeAllListeners] }
  

.id

thread.id -> A sequential thread serial number.

.version

thread.version -> A string with the threads_a_gogo version number.

.load( path [, cb] )

thread.load( path [, cb] ) -> thread

Loads the file at path and thread.eval(fileContents, cb).

NOTE that most methods return the thread object so that calls can be chained like this: thread.load("boot.js").eval("boot()").emit("go").on("event", cb) ...

.eval( program [, cb])

thread.eval( program [, cb]) -> thread

Converts program.toString() and eval()s (which is the equivalent of loading a script in a browser) it in the thread's global context, and (if provided) returns to a callback the completion value: cb(err, completionValue). Some examples you can try in node's console, but first please declare a function cb (a,b) { console.log(a,b) }, that will be handy, then type thread.eval("Math.random()", cb) the thread will run that (Math.random()) and the cb(err,result) will get (and display) a null (random number). A thread.eval('function hello () { puts("Hello!"); return "world!" }', cb) will eval that in the global context of the thread and thus create a global function hello in the thread's js global context and your cb(err,result) will get null undefined in the result, null because there were no errors and undefined because the completion value of a function declaration is undefined. On the plus side, now you have injected for the first time in your life some js code of yours in a TAGG's thread and you can tell it to run that, do a thread.eval('hello()',cb) and the thread will print Hello! in the console and the cb(err,result) will receive world! into result. How cool is that?

.on( eventType, listener )

thread.on( eventType, listener ) -> thread

Registers the listener listener(data [, data2 ... ]) for any events of eventType that the thread thread may emit. For example, declare a function cb (a,b,c) { console.log(a,b,c) } and then do thread.on("event", cb). Now whenever the thread emits an event of the type event (which by the way can be any arbitrary name/string you choose), cb will be triggered. Let's do that with a thread.eval('i=5; while (i--) thread.emit("event", "How", "cool", "is that?")') and the console will display How cool is that? five times, huh, unbelievable.

.once( eventType, listener )

thread.once( eventType, listener ) -> thread

Like thread.on(), but the listener will only be triggered once.

.removeAllListeners( [eventType] )

thread.removeAllListeners( [eventType] ) -> thread

Deletes all listeners for all eventTypes unless eventType is provided, in which case it deletes the listeners only of the event type eventType.

.emit( eventType, eventData [, eventData ... ] )

thread.emit( eventType, eventData [, eventData ... ] ) -> thread

Emit an event of eventType with eventData in the thread thread. All its arguments are .toString()ed.

.destroy( [ rudely ] )

thread.destroy( [0 (nicely) | 1 (rudely)] [, cb]) -> undefined

Destroys the thread. If the first parameter is not provided or falsy or 0 (the default) the thread will keep running until both its nextTick/setImmediate queue and its pending .eval() jobs queue are empty. If it's truthy or 1 (rudely) the thread's event loop will exit as soon as possible, regardless. If a callback cb (optional) is provided, it will be called when the thread has been killed and completely destroyed, the cb will receive no arguments and the receiver (its 'this') points to the global object. If the thread is stuck in a while (1) ; or similar it won't end and currently tagg has no way around that.

_on

Ignore, don't touch that. The _on object holds the event listeners.


Thread object API (this is the thread object that exists not in node but as a global in every thread)

Inside every thread .create()d by threads_a_gogo, there's a global thread object with these properties:

thread (a global) ->

{ id: 0,
  version: '0.1.13',
  on: [Function: on],
  once: [Function: once],
  emit: [Function: emit],
  removeAllListeners: [Function: removeAllListeners]
  nextTick: [Function: nextTick],
  _on: {},
  _ntq: [] }

.id

thread.id -> the serial number of this thread.

.version

thread.version -> A string with the threads_a_gogo version number.

.on( eventType, listener )

thread.on( eventType, listener ) -> thread

Just like thread.on() above. But in this case it will receive events emitted by node's main thread, because, remeber, all this exists in the thread's own js context which is totally independent of node's js context.

.once( eventType, listener )

thread.once( eventType, listener ) -> thread

Just like thread.once() above.

.emit( eventType, eventData [, eventData ... ] )

thread.emit( eventType, eventData [, eventData ... ] ) -> thread

Just like thread.emit() above. What this emits will trigger a listener (if set) in node's main thread.

.removeAllListeners( [eventType] )

thread.removeAllListeners( [eventType] ) -> thread

Just like thread.removeAllListeners() above.

.nextTick( function )

thread.nextTick( function ) -> undefined

Like setImmediate(), but twice as fast. Every thread runs its own event loop. First it looks for any .eval()s that node may have sent, if there are any it runs the first one, after that it looks in the nextTick/setImmediate queue, if there are any functions there to run, it runs them all (but only in chunks of up to 8192 so that nextTick/setImmediate can never totally block a thread), and then looks again to see if there are any more .eval() events, if there are runs the first one, and repeats this loop forever until there are no more .eval() events nor nextTick/setImmediate functions at which point the thread goes to sleep until any further .eval()s or .emit()s sent from node awake it.

_on

Ignore, don't touch that. The _on object holds the event listeners.

_ntq

Ignore, don't touch that. The _ntq array holds the nextTick()ed and/or setImmediate()d funcitons.


Globals in the threads' js contexts

Inside every thread .create()d by threads_a_gogo, on top of the usual javascript ones there's these other globals:

puts(arg1 [, arg2 ...])

puts(arg1 [, arg2 ...]) -> undefined

.toString()s and fprintf(stdout)s and fflush(stdout)es its arguments to (you guessed it) stdout.

setImmediate(function)

setImmediate( function ) -> undefined

Just an alias for thread.nextTick(function).

thread

The thread object described above is also a global.


Thread pool API

pool= tagg.createPool( numbreOfThreads ) ->

{ load: [Function: load],
  on: [Function: on],
  any: 
   { eval: [Function: evalAny],
     emit: [Function: emitAny] },
  all: 
   { eval: [Function: evalAll],
     emit: [Function: emitAll] },
  totalThreads: [Function: getTotalThreads],
  idleThreads: [Function: getIdleThreads],
  pendingJobs: [Function: getPendingJobs],
  destroy: [Function: destroy],
  pool: 
   [ { load: [Function: load],
       eval: [Function: eval],
       emit: [Function: emit],
       destroy: [Function: destroy],
       id: 0,
       version: '0.1.13',
       on: [Function: on],
       once: [Function: once],
       _on: {},
       removeAllListeners: [Function: removeAllListeners] } ] }

.load( path [, cb] )

pool.load( path [, cb] ) -> pool

thread.load( path [, cb] ) in every one of the pool's threads. The cb will be called as many times as threads there are.

.on( eventType, listener )

pool.on( eventType, listener ) -> pool

Registers a listener for events of eventType. Any events of eventType emitted by any thread of the pool will trigger that cb/listener. For example, if you set a pool.on("event", cb) and any thread does a thread.emit("event", "Hi", "there"), a cb(a,b) will receive "Hi" in a and "There" in b.

.any.eval( program, cb )

pool.any.eval( program, cb ) -> pool

Like thread.eval(), but in any of the pool's threads.

.any.emit( eventType, eventData [, eventData ... ] )

pool.any.emit( eventType, eventData [, eventData ... ] ) -> pool

Like thread.emit() but in any of the pool's threads.

.all.eval( program, cb )

pool.all.eval( program, cb ) -> pool

Like thread.eval(), but in all the pool's threads.

.all.emit( eventType, eventData [, eventData ... ] )

pool.all.emit( eventType, eventData [, eventData ... ] ) -> pool

Like thread.emit() but in all the pool's threads.

.totalThreads()

pool.totalThreads() -> returns the number of threads in this pool: as supplied in .createPool( number ). It's also the same as pool.pool.length.

.idleThreads()

pool.idleThreads() -> returns the number of threads in this pool that are currently idle. Does not work very well currently. Better don't use it.

.pendingJobs()

threadPool.pendingJobs() -> returns the number of jobs pending. Does not work very well currently. Better don't use it.

.destroy( [ rudely ] )

pool.destroy( [ rudely ] ) -> undefined

If rudely is 0 or falsy the thread will exit when there aren't any more events in its events queue. If rudely it will quit regardless of that. If stuck in a while (1) ; or similar it won't and currently tagg has no way around that. At least not yet. Pull requests are very much welcomed, just so you know.

.pool

pool.pool is an array that contains all the threads in the thread pool for your tinkering pleasure.

Rationale

Node.js is the most awesome, cute and super-sexy piece of free, open source software.

Its event loop can spin as fast and smooth as a turbo, and roughly speaking, the faster it spins, the more power it delivers. That's why @ryah took great care to ensure that no -possibly slow- I/O operations could ever block it: a pool of background threads (thanks to Marc Lehmann's libeio library) handle any blocking I/O calls in the background, in parallel.

In Node it's verboten to write a server like this:

http.createServer(function (req,res) {
  res.end( fs.readFileSync(path) );
}).listen(port);

Because synchronous I/O calls block the turbo, and without proper boost, Node.js begins to stutter and behaves clumsily. To avoid it there's the asynchronous version of .readFile(), in continuation passing style, that takes a callback:

fs.readfile(path, function cb (err, data) { /* ... */ });

It's cool, we love it (*), and there's hundreds of ad hoc built-in functions like this in Node to help us deal with almost any variety of possibly slow, blocking I/O.

But what's with longish, CPU-bound tasks?

How do you avoid blocking the event loop, when the task at hand isn't I/O bound, and lasts more than a few fractions of a millisecond?

http.createServer(function cb (req,res) {
  res.end( fibonacci(40) );
}).listen(port);

You simply can't, because there's no way... well, there wasn't before threads_a_gogo.

What is Threads A GoGo for Node.js

threads_a_gogo provides the asynchronous API for CPU-bound tasks that's missing in Node.js. Both in continuation passing style (callbacks), and in event emitter style (event listeners).

The same API Node uses to delegate a longish I/O task to a background (libeio) thread:

asyncIOTask(what, cb);

threads_a_gogo uses to delegate a longish CPU task to a background (JavaScript) thread:

thread.eval(program, cb);

So with threads_a_gogo you can write:

http.createServer(function (req,res) {
  thread.eval('fibonacci(40)', function cb (err, data) {
    res.end(data);
  });
}).listen(port);

And it won't block the event loop because the fibonacci(40) will run in parallel in a separate background thread.

Why Threads

Threads (kernel threads) are very interesting creatures. They provide:

1.- Parallelism: All the threads run in parallel. On a single core processor, the CPU is switched rapidly back and forth among the threads providing the illusion that the threads are running in parallel, albeit on a slower CPU than the real one. With 10 compute-bound threads in a process, the threads would appear to be running in parallel, each one on a CPU with 1/10th the speed of the real CPU. On a multi-core processor, threads are truly running in parallel, and get time-sliced when the number of threads exceed the number of cores. So with 12 compute bound threads on a quad-core processor each thread will appear to run at 1/3rd of the nominal core speed.

2.- Fairness: No thread is more important than another, cores and CPU slices are fairly distributed among threads by the OS scheduler.

3.- Threads fully exploit all the available CPU resources in your system. On a loaded system running many tasks in many threads, the more cores there are, the faster the threads will complete. Automatically.

4.- The threads of a process share exactly the same address space, that of the process they belong to. Every thread can access every memory address within the process' address space. This is a very appropriate setup when the threads are actually part of the same job and are actively and closely cooperating with each other. Passing a reference to a chunk of data via a pointer is many orders of magnitude faster than transferring a copy of the data via IPC.

Why not multiple processes.

The "can't block the event loop" problem is inherent to Node's evented model. No matter how many Node processes you have running as a Node-cluster, it won't solve its issues with CPU-bound tasks.

Launch a cluster of N Nodes running the example B (quickIntro_blocking.js) above, and all you'll get is N -instead of one- Nodes with their event loops blocked and showing a sluggish performance.

node-threads-a-gogo's People

Contributors

fmgdias avatar xk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-threads-a-gogo's Issues

i386 architecture

Hello,

I can't run this module.

The installation went fine ('install' finished successfully (1.542s)).

This is what i get while trying to launch my node app.js

node_modules/node-threads/build/release/threads_a_gogo.node: mach-o, but wrong architecture.

I'm running nodejs v0.8.18 on a Mac Os X (Mountain Lion)

Regards.

Passing objects through emit functions

Hey is it possible to pass objects to a child thread? For instance.

var thread = require('threads_a_gogo').create();
thread.load(path.resolve(__dirname, './file.js'));

thread.emit('doSomething', { i: 'am', so: 'cool' });

When I currently do this, it's passing it as a string.

Thanks

node 0.12.x support

Got some error
(I'm not good at this, can you help?)

/

[email protected] install /home/node/zgws/web_open/node_modules/threads_a_gogo
node-gyp rebuild

child_process: customFds option is deprecated, use stdio instead.
make: Entering directory /home/node/zgws/web_open/node_modules/threads_a_gogo/build' CXX(target) Release/obj.target/threads_a_gogo/src/threads_a_gogo.o ../src/threads_a_gogo.cc:34:3: error: ‘uv_async_t’ does not name a type uv_async_t async_watcher; //MUST be the first one ^ ../src/threads_a_gogo.cc: In function ‘typeThread* isAThread(v8::Handle<v8::Object>)’: ../src/threads_a_gogo.cc:130:39: error: ‘class v8::Object’ has no member named ‘GetPointerFromInternalField’ thread= (typeThread*) receiver->GetPointerFromInternalField(0); ^ ../src/threads_a_gogo.cc: At global scope: ../src/threads_a_gogo.cc:159:34: error: ‘Arguments’ does not name a type static Handle<Value> Puts (const Arguments &args) { ^ ../src/threads_a_gogo.cc:159:45: error: ISO C++ forbids declaration of ‘args’ with no type [-fpermissive] static Handle<Value> Puts (const Arguments &args) { ^ In file included from ../src/threads_a_gogo.cc:4:0: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h: In function ‘v8::Handle<v8::Value> Puts(const int&)’: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:816:13: error: ‘v8::HandleScope::HandleScope()’ is protected V8_INLINE HandleScope() {} ^ ../src/threads_a_gogo.cc:162:15: error: within this context HandleScope scope; ^ ../src/threads_a_gogo.cc:164:19: error: request for member ‘Length’ in ‘args’, which is of non-class type ‘const int’ while (i < args.Length()) { ^ ../src/threads_a_gogo.cc:165:35: error: invalid types ‘const int[int]’ for array subscript String::Utf8Value c_str(args[i]); ^ ../src/threads_a_gogo.cc:172:20: error: too few arguments to function ‘v8::Handle<v8::Primitive> v8::Undefined(v8::Isolate*)’ return Undefined(); ^ In file included from ../src/threads_a_gogo.cc:4:0: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:305:28: note: declared here friend Handle<Primitive> Undefined(Isolate* isolate); ^ ../src/threads_a_gogo.cc: In function ‘void* aThread(void*)’: ../src/threads_a_gogo.cc:190:34: error: no matching function for call to ‘v8::Isolate::SetData(typeThread*&)’ thread->isolate->SetData(thread); ^ ../src/threads_a_gogo.cc:190:34: note: candidate is: In file included from ../src/threads_a_gogo.cc:4:0: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:6642:6: note: void v8::Isolate::SetData(uint32_t, void*) void Isolate::SetData(uint32_t slot, void* data) { ^ /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:6642:6: note: candidate expects 2 arguments, 1 provided ../src/threads_a_gogo.cc:208:26: error: ‘struct typeThread’ has no member named ‘async_watcher’ uv_async_send(&thread->async_watcher); ^ ../src/threads_a_gogo.cc:208:39: error: ‘uv_async_send’ was not declared in this scope uv_async_send(&thread->async_watcher); ^ ../src/threads_a_gogo.cc: At global scope: ../src/threads_a_gogo.cc:220:40: error: ‘Arguments’ does not name a type static Handle<Value> threadEmit (const Arguments &args); ^ ../src/threads_a_gogo.cc:220:51: error: ISO C++ forbids declaration of ‘args’ with no type [-fpermissive] static Handle<Value> threadEmit (const Arguments &args); ^ ../src/threads_a_gogo.cc: In function ‘void eventLoop(typeThread*)’: ../src/threads_a_gogo.cc:224:33: error: no matching function for call to ‘v8::Context::New()’ thread->context= Context::New(); ^ ../src/threads_a_gogo.cc:224:33: note: candidate is: In file included from ../src/threads_a_gogo.cc:4:0: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:5263:25: note: static v8::Local<v8::Context> v8::Context::New(v8::Isolate*, v8::ExtensionConfiguration*, v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Value>) static Local<Context> New( ^ /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:5263:25: note: candidate expects 4 arguments, 0 provided ../src/threads_a_gogo.cc:225:18: error: base operand of ‘->’ has non-pointer type ‘v8::Persistent<v8::Context>’ thread->context->Enter(); ^ In file included from ../src/threads_a_gogo.cc:4:0: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:816:13: error: ‘v8::HandleScope::HandleScope()’ is protected V8_INLINE HandleScope() {} ^ ../src/threads_a_gogo.cc:228:17: error: within this context HandleScope scope1; ^ ../src/threads_a_gogo.cc:230:42: error: base operand of ‘->’ has non-pointer type ‘v8::Persistent<v8::Context>’ Local<Object> global= thread->context->Global(); ^ ../src/threads_a_gogo.cc:231:17: error: ‘NewSymbol’ is not a member of ‘v8::String’ global->Set(String::NewSymbol("puts"), FunctionTemplate::New(Puts)->GetFunction()); ^ ../src/threads_a_gogo.cc:231:70: error: no matching function for call to ‘v8::FunctionTemplate::New(v8::Handle<v8::Value> (&)(const int&))’ global->Set(String::NewSymbol("puts"), FunctionTemplate::New(Puts)->GetFunction()); ^ ../src/threads_a_gogo.cc:231:70: note: candidate is: In file included from ../src/threads_a_gogo.cc:4:0: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:3455:34: note: static v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate*, v8::FunctionCallback, v8::Handle<v8::Value>, v8::Handle<v8::Signature>, int) static Local<FunctionTemplate> New( ^ /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:3455:34: note: no known conversion for argument 1 from ‘v8::Handle<v8::Value>(const int&)’ to ‘v8::Isolate*’ ../src/threads_a_gogo.cc:232:45: error: no matching function for call to ‘v8::Object::New()’ Local<Object> threadObject= Object::New(); ^ ../src/threads_a_gogo.cc:232:45: note: candidate is: In file included from ../src/threads_a_gogo.cc:4:0: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:2388:24: note: static v8::Local<v8::Object> v8::Object::New(v8::Isolate*) static Local<Object> New(Isolate* isolate); ^ /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:2388:24: note: candidate expects 1 argument, 0 provided ../src/threads_a_gogo.cc:233:17: error: ‘NewSymbol’ is not a member of ‘v8::String’ global->Set(String::NewSymbol("thread"), threadObject); ^ ../src/threads_a_gogo.cc:235:23: error: ‘NewSymbol’ is not a member of ‘v8::String’ threadObject->Set(String::NewSymbol("id"), Number::New(thread->id)); ^ ../src/threads_a_gogo.cc:235:70: error: no matching function for call to ‘v8::Number::New(long int&)’ threadObject->Set(String::NewSymbol("id"), Number::New(thread->id)); ^ ../src/threads_a_gogo.cc:235:70: note: candidate is: In file included from ../src/threads_a_gogo.cc:4:0: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:1999:24: note: static v8::Local<v8::Number> v8::Number::New(v8::Isolate*, double) static Local<Number> New(Isolate* isolate, double value); ^ /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:1999:24: note: candidate expects 2 arguments, 1 provided ../src/threads_a_gogo.cc:236:23: error: ‘NewSymbol’ is not a member of ‘v8::String’ threadObject->Set(String::NewSymbol("emit"), FunctionTemplate::New(threadEmit)->GetFunction()); ^ ../src/threads_a_gogo.cc:236:82: error: no matching function for call to ‘v8::FunctionTemplate::New(v8::Handle<v8::Value> (&)(const int&))’ threadObject->Set(String::NewSymbol("emit"), FunctionTemplate::New(threadEmit)->GetFunction()); ^ ../src/threads_a_gogo.cc:236:82: note: candidate is: In file included from ../src/threads_a_gogo.cc:4:0: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:3455:34: note: static v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate*, v8::FunctionCallback, v8::Handle<v8::Value>, v8::Handle<v8::Signature>, int) static Local<FunctionTemplate> New( ^ /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:3455:34: note: no known conversion for argument 1 from ‘v8::Handle<v8::Value>(const int&)’ to ‘v8::Isolate*’ ../src/threads_a_gogo.cc:237:51: error: ‘New’ is not a member of ‘v8::String’ Local<Object> dispatchEvents= Script::Compile(String::New(kEvents_js))->Run()->ToObject()->CallAsFunction(threadObject, 0, NULL)->ToObject(); ^ ../src/threads_a_gogo.cc:238:54: error: ‘New’ is not a member of ‘v8::String’ Local<Object> dispatchNextTicks= Script::Compile(String::New(kThread_nextTick_js))->Run()->ToObject(); ^ ../src/threads_a_gogo.cc:239:56: error: ‘NewSymbol’ is not a member of ‘v8::String’ Local<Array> _ntq= (v8::Array*) *threadObject->Get(String::NewSymbol("_ntq")); ^ In file included from ../src/threads_a_gogo.cc:4:0: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:816:13: error: ‘v8::HandleScope::HandleScope()’ is protected V8_INLINE HandleScope() {} ^ ../src/threads_a_gogo.cc:251:21: error: within this context HandleScope scope2; ^ ../src/threads_a_gogo.cc:265:13: error: ‘IdleNotification’ is not a member of ‘v8::V8’ V8::IdleNotification(); ^ ../src/threads_a_gogo.cc:273:23: error: ‘New’ is not a member of ‘v8::String’ source= String::New(**str, (*str).length()); ^ ../src/threads_a_gogo.cc:277:23: error: ‘New’ is not a member of ‘v8::String’ source= String::New(job->typeEval.scriptText_CharPtr); ^ ../src/threads_a_gogo.cc:281:21: error: ‘New’ is not a member of ‘v8::Script’ script= Script::New(source); ^ ../src/threads_a_gogo.cc:291:38: error: ‘struct typeThread’ has no member named ‘async_watcher’ uv_async_send(&thread->async_watcher); ^ ../src/threads_a_gogo.cc:291:51: error: ‘uv_async_send’ was not declared in this scope uv_async_send(&thread->async_watcher); ^ ../src/threads_a_gogo.cc:307:22: error: ‘New’ is not a member of ‘v8::String’ args[0]= String::New(**str, (*str).length()); ^ ../src/threads_a_gogo.cc:310:65: error: invalid conversion from ‘int’ to ‘v8::Isolate*’ [-fpermissive] Local<Array> array= Array::New(job->typeEvent.length); ^ In file included from ../src/threads_a_gogo.cc:4:0: /home/node/.node-gyp/0.12.0/deps/v8/include/v8.h:2417:23: error: initializing argument 1 of ‘static v8::Local<v8::Array> v8::Array::New(v8::Isolate*, int)’ [-fpermissive] static Local<Array> New(Isolate* isolate, int length = 0); ^ ../src/threads_a_gogo.cc:316:29: error: ‘New’ is not a member of ‘v8::String’ array->Set(i, String::New(**str, (*str).length())); ^ ../src/threads_a_gogo.cc:331:13: error: ‘IdleNotification’ is not a member of ‘v8::V8’ V8::IdleNotification(); ^ ../src/threads_a_gogo.cc:358:19: error: ‘class v8::Persistent<v8::Context>’ has no member named ‘Dispose’ thread->context.Dispose(); ^ ../src/threads_a_gogo.cc: In function ‘void destroyaThread(typeThread*)’: ../src/threads_a_gogo.cc:372:19: error: base operand of ‘->’ has non-pointer type ‘v8::Persistent<v8::Object>’ thread->JSObject->SetPointerInInternalField(0, NULL); ^ ../src/threads_a_gogo.cc:373:20: error: ‘class v8::Persistent<v8::Object>’ has no member named ‘Dispose’ thread->JSObject.Dispose(); ^ ../src/threads_a_gogo.cc:376:13: error: ‘uv_handle_t’ was not declared in this scope uv_close((uv_handle_t*) &thread->async_watcher, NULL); ^ ../src/threads_a_gogo.cc:376:25: error: expected primary-expression before ‘)’ token uv_close((uv_handle_t*) &thread->async_watcher, NULL); ^ ../src/threads_a_gogo.cc:376:36: error: ‘struct typeThread’ has no member named ‘async_watcher’ uv_close((uv_handle_t*) &thread->async_watcher, NULL); ^ ../src/threads_a_gogo.cc:376:55: error: ‘uv_close’ was not declared in this scope uv_close((uv_handle_t*) &thread->async_watcher, NULL); ^ ../src/threads_a_gogo.cc: At global scope: ../src/threads_a_gogo.cc:400:3: error: variable or field ‘Callback’ declared void uv_async_t *watcher ^ ../src/threads_a_gogo.cc:400:3: error: ‘uv_async_t’ was not declared in this scope ../src/threads_a_gogo.cc:400:15: error: ‘watcher’ was not declared in this scope uv_async_t *watcher ^ ../src/threads_a_gogo.cc:404:3: error: expected primary-expression before ‘int’ , int revents) { ^ In file included from ../src/threads_a_gogo.cc:19:0: ../src/queues_a_gogo.cc:151:13: warning: ‘void initQueues()’ defined but not used [-Wunused-function] static void initQueues (void) { ^ In file included from ../src/threads_a_gogo.cc:99:0: ../src/createPool.js.c:1:20: warning: ‘kCreatePool_js’ defined but not used [-Wunused-variable] static const char* kCreatePool_js= "\n\x28\x66\x75\x6e\x63\x74\x69\x6f\x6e \x63\x72\x65\x61\x74\x65\x50\x6f\x6f\x6c\x28\x6e\x29\x7b\x27\x75\x73\x65 \x73\x74\x72\x69\x63\x74\x27\x3b\x76\x61\x72 \x54\x3d\x74\x68\x69\x73\x3b\x6e\x3d\x4d\x61\x74\x68\x2e\x66\x6c\x6f\x6f\x72\x28\x6e\x29\x3b\x69\x66\x28\x21\x28\x6e\x3e\x30\x29\x29\x7b\x74\x68\x72\x6f\x77\x27\x2e\x63\x72\x65\x61\x74\x65\x50\x6f\x6f\x6c\x28 \x6e\x75\x6d\x4f\x66\x54\x68\x72\x65\x61\x64\x73 \x29\x3a \x6e\x75\x6d\x4f\x66\x54\x68\x72\x65\x61\x64\x73 \x6d\x75\x73\x74 \x62\x65 \x61 \x4e\x75\x6d\x62\x65\x72 \x3e \x30\x27\x3b\x7d\n\x76\x61\x72 \x6b\x54\x79\x70\x65\x52\x75\x6e\x3d\x31\x3b\x76\x61\x72 \x6b\x54\x79\x70\x65\x45\x6d\x69\x74\x3d\x32\x3b\x76\x61\x72 \x70\x6f\x6f\x6c\x3d\x5b\x5d\x3b\x76\x61\x72 \x69\x64\x6c\x65\x54\x68\x72\x65\x61\x64\x73\x3d\x5b\x5d\x3b\x76\x61\x72 \x71\x3d\x7b\x66\x69\x72\x73\x74\x3a\x6e\x75\x6c\x6c\x2c\x6c\x61\x73\x74\x3a\x6e\x75\x6c\x6c\x2c\x6c\x65\x6e\x67\x74\x68\x3a\x30\x7d\x3b\x76\x61\x72 \x70\x6f\x6f\x6c\x4f\x62\x6a\x65\x63\x74\x3d\x7b\x61\x6e\x79\x3a\x7b\x65\x76\x61\x6c\x3a\x65\x76\x61\x6c\x41\x6e\x79\x2c\x65\x6d\x69\x74\x3a\x65\x6d\x69\x74\x41\x6e\x79\x7d\x2c\x61\x6c\x6c\x3a\x7b\x65\x76\x61\x6c\x3a\x65\x76\x61\x6c\x41\x6c\x6c\x2c\x65\x6d\x69\x74\x3a\x65\x6d\x69\x74\x41\x6c\x6c\x7d\x2c\x6f\x6e\x3a\x6f\x6e\x2c\x74\x6f\x74\x61\x6c\x54\x68\x72\x65\x61\x64\x73\x3a\x66\x75\x6e\x63\x74\x69\x6f\x6e \x67\x65\x74\x4e\x75\x6d\x54\x68\x72\x65\x61\x64\x73\x28\x29\x7b\x72\x65\x74\x75\x72\x6e \x70\x6f\x6f\x6c\x2e\x6c\x65\x6e\x67\x74\x68\x7d\x2c\x69\x64\x6c\x65\x54\x68\x72\x65\x61\x64\x73\x3a\x66\x75\x6e\x63\x74\x69\x6f\x6e \x67\x65\x74\x49\x64\x6c\x65\x54\x68\x72\x65\x61\x64\x73\x28\x29\x7b\x72\x65\x74\x75\x72\x6e \x69\x64\x6c\x65\x54\x68\x72\x65\x61\x64\x73\x2e\x6c\x65\x6e\x67\x74\x68\x7d\x2c\x70\x65\x6e\x64\x69\x6e\x67\x4a\x6f\x62\x73\x3a\x66\x75\x6e\x63\x74\x69\x6f\x6e \x67\x65\x74\x50\x65\x6e\x64\x69\x6e\x67\x4a\x6f\x62\x73\x28\x29\x7b\x72\x65\x74\x75\x72\x6e \x71\x2e\x6c\x65\x6e\x67\x74\x68\x7d\x2c\x64\x65\x73\x74\x72\x6f\x79\x3a\x64\x65\x73\x74\x72\x6f\x79\x2c\x6c\x6f\x61\x64\x3a\x70\x6f\x6f\x6c\x4c\x6f\x61\x64\x7d\x3b\x74\x72\x79\x7b\x77\x68\x69\x6c\x65\x28\x6e\x2d\x2d\x29\x7b\x70\x6f\x6f\x6c\x5b\x6e\x5d\x3d\x69\x64\x6c\x65\x54\x68\x72\x65\x61\x64\x73\x5b\x6e\x5d\x3d\x54\x2e\x63\x72\x65\x61\x74\x65\x28\x29\x3b\x7d\x7d\n\x63\x61\x74\x63\x68\x28\x65\x29\x7b\x64\x65\x73\x74\x72\x6f\x79\x28\x31\x29\x3b\x74\x68\x72\x6f\x77 \x65\x3b\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x70\x6f\x6f\x6c\x4c\x6f\x61\x64\x28\x70\x61\x74\x68\x2c\x63\x62\x29\x7b\x76\x61\x72 \x69\x3d\x70\x6f\x6f\x6c\x2e\x6c\x65\x6e\x67\x74\x68\x3b\x77\x68\x69\x6c\x65\x28\x69\x2d\x2d\x29\x7b\x70\x6f\x6f\x6c\x5b\x69\x5d\x2e\x6c\x6f\x61\x64\x28\x70\x61\x74\x68\x2c\x63\x62\x29\x3b\x7d\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x6e\x65\x78\x74\x4a\x6f\x62\x28\x74\x29\x7b\x76\x61\x72 \x6a\x6f\x62\x3d\x71\x50\x75\x6c\x6c\x28\x29\x3b\x69\x66\x28\x6a\x6f\x62\x29\x7b\x69\x66\x28\x6a\x6f\x62\x2e\x74\x79\x70\x65\x3d\x3d\x3d\x6b\x54\x79\x70\x65\x52\x75\x6e\x29\x7b\x74\x2e\x65\x76\x61\x6c\x28\x6a\x6f\x62\x2e\x73\x72\x63\x54\x65\x78\x74\x4f\x72\x45\x76\x65\x6e\x74\x54\x79\x70\x65\x2c\x66\x75\x6e\x63\x74\x69\x6f\x6e \x69\x64\x6c\x65\x43\x42\x28\x65\x2c\x64\x29\x7b\x6e\x65\x78\x74\x4a\x6f\x62\x28\x74\x29\x3b\x76\x61\x72 \x66\x3d\x6a\x6f\x62\x2e\x63\x62\x4f\x72\x44\x61\x74\x61\x3b\x69\x66\x28\x66\x29\x7b\x6a\x6f\x62\x2e\x63\x62\x4f\x72\x44\x61\x74\x61\x2e\x63\x61\x6c\x6c\x28\x74\x2c\x65\x2c\x64\x29\x3b\x7d\x7d\x29\x3b\x7d\n\x65\x6c\x73\x65 \x69\x66\x28\x6a\x6f\x62\x2e\x74\x79\x70\x65\x3d\x3d\x3d\x6b\x54\x79\x70\x65\x45\x6d\x69\x74\x29\x7b\x74\x2e\x65\x6d\x69\x74\x28\x6a\x6f\x62\x2e\x73\x72\x63\x54\x65\x78\x74\x4f\x72\x45\x76\x65\x6e\x74\x54\x79\x70\x65\x2c\x6a\x6f\x62\x2e\x63\x62\x4f\x72\x44\x61\x74\x61\x29\x3b\x6e\x65\x78\x74\x4a\x6f\x62\x28\x74\x29\x3b\x7d\x7d\n\x65\x6c\x73\x65\x7b\x69\x64\x6c\x65\x54\x68\x72\x65\x61\x64\x73\x2e\x70\x75\x73\x68\x28\x74\x29\x3b\x7d\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x71\x50\x75\x73\x68\x28\x73\x72\x63\x54\x65\x78\x74\x4f\x72\x45\x76\x65\x6e\x74\x54\x79\x70\x65\x2c\x63\x62\x4f\x72\x44\x61\x74\x61\x2c\x74\x79\x70\x65\x29\x7b\x76\x61\x72 \x6a\x6f\x62\x3d\x7b\x6e\x65\x78\x74\x3a\x6e\x75\x6c\x6c\x2c\x73\x72\x63\x54\x65\x78\x74\x4f\x72\x45\x76\x65\x6e\x74\x54\x79\x70\x65\x3a\x73\x72\x63\x54\x65\x78\x74\x4f\x72\x45\x76\x65\x6e\x74\x54\x79\x70\x65\x2c\x63\x62\x4f\x72\x44\x61\x74\x61\x3a\x63\x62\x4f\x72\x44\x61\x74\x61\x2c\x74\x79\x70\x65\x3a\x74\x79\x70\x65\x7d\x3b\x69\x66\x28\x71\x2e\x6c\x61\x73\x74\x29\x7b\x71\x2e\x6c\x61\x73\x74\x2e\x6e\x65\x78\x74\x3d\x6a\x6f\x62\x3b\x71\x2e\x6c\x61\x73\x74\x3d\x6a\x6f\x62\x3b\x7d\n\x65\x6c\x73\x65\x7b\x71\x2e\x66\x69\x72\x73\x74\x3d\x71\x2e\x6c\x61\x73\x74\x3d\x6a\x6f\x62\x3b\x7d\n\x71\x2e\x6c\x65\x6e\x67\x74\x68\x2b\x2b\x3b\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x71\x50\x75\x6c\x6c\x28\x29\x7b\x76\x61\x72 \x6a\x6f\x62\x3d\x71\x2e\x66\x69\x72\x73\x74\x3b\x69\x66\x28\x6a\x6f\x62\x29\x7b\x69\x66\x28\x71\x2e\x6c\x61\x73\x74\x3d\x3d\x3d\x6a\x6f\x62\x29\x7b\x71\x2e\x66\x69\x72\x73\x74\x3d\x71\x2e\x6c\x61\x73\x74\x3d\x6e\x75\x6c\x6c\x3b\x7d\n\x65\x6c\x73\x65\x7b\x71\x2e\x66\x69\x72\x73\x74\x3d\x6a\x6f\x62\x2e\x6e\x65\x78\x74\x3b\x7d\n\x71\x2e\x6c\x65\x6e\x67\x74\x68\x2d\x2d\x3b\x7d\n\x72\x65\x74\x75\x72\x6e \x6a\x6f\x62\x3b\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x65\x76\x61\x6c\x41\x6e\x79\x28\x73\x72\x63\x2c\x63\x62\x29\x7b\x71\x50\x75\x73\x68\x28\x73\x72\x63\x2c\x63\x62\x2c\x6b\x54\x79\x70\x65\x52\x75\x6e\x29\x3b\x69\x66\x28\x69\x64\x6c\x65\x54\x68\x72\x65\x61\x64\x73\x2e\x6c\x65\x6e\x67\x74\x68\x29\x7b\x6e\x65\x78\x74\x4a\x6f\x62\x28\x69\x64\x6c\x65\x54\x68\x72\x65\x61\x64\x73\x2e\x70\x6f\x70\x28\x29\x29\x3b\x7d\n\x72\x65\x74\x75\x72\x6e \x70\x6f\x6f\x6c\x4f\x62\x6a\x65\x63\x74\x3b\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x65\x76\x61\x6c\x41\x6c\x6c\x28\x73\x72\x63\x2c\x63\x62\x29\x7b\x70\x6f\x6f\x6c\x2e\x66\x6f\x72\x45\x61\x63\x68\x28\x66\x75\x6e\x63\x74\x69\x6f\x6e\x28\x76\x2c\x69\x2c\x6f\x29\x7b\x76\x2e\x65\x76\x61\x6c\x28\x73\x72\x63\x2c\x63\x62\x29\x3b\x7d\x29\x3b\x72\x65\x74\x75\x72\x6e \x70\x6f\x6f\x6c\x4f\x62\x6a\x65\x63\x74\x3b\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x65\x6d\x69\x74\x41\x6e\x79\x28\x65\x76\x65\x6e\x74\x2c\x64\x61\x74\x61\x29\x7b\x71\x50\x75\x73\x68\x28\x65\x76\x65\x6e\x74\x2c\x64\x61\x74\x61\x2c\x6b\x54\x79\x70\x65\x45\x6d\x69\x74\x29\x3b\x69\x66\x28\x69\x64\x6c\x65\x54\x68\x72\x65\x61\x64\x73\x2e\x6c\x65\x6e\x67\x74\x68\x29\x7b\x6e\x65\x78\x74\x4a\x6f\x62\x28\x69\x64\x6c\x65\x54\x68\x72\x65\x61\x64\x73\x2e\x70\x6f\x70\x28\x29\x29\x3b\x7d\n\x72\x65\x74\x75\x72\x6e \x70\x6f\x6f\x6c\x4f\x62\x6a\x65\x63\x74\x3b\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x65\x6d\x69\x74\x41\x6c\x6c\x28\x65\x76\x65\x6e\x74\x2c\x64\x61\x74\x61\x29\x7b\x70\x6f\x6f\x6c\x2e\x66\x6f\x72\x45\x61\x63\x68\x28\x66\x75\x6e\x63\x74\x69\x6f\x6e\x28\x76\x2c\x69\x2c\x6f\x29\x7b\x76\x2e\x65\x6d\x69\x74\x28\x65\x76\x65\x6e\x74\x2c\x64\x61\x74\x61\x29\x3b\x7d\x29\x3b\x72\x65\x74\x75\x72\x6e \x70\x6f\x6f\x6c\x4f\x62\x6a\x65\x63\x74\x3b\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x6f\x6e\x28\x65\x76\x65\x6e\x74\x2c\x63\x62\x29\x7b\x70\x6f\x6f\x6c\x2e\x66\x6f\x72\x45\x61\x63\x68\x28\x66\x75\x6e\x63\x74\x69\x6f\x6e\x28\x76\x2c\x69\x2c\x6f\x29\x7b\x76\x2e\x6f\x6e\x28\x65\x76\x65\x6e\x74\x2c\x63\x62\x29\x3b\x7d\x29\x3b\x72\x65\x74\x75\x72\x6e \x74\x68\x69\x73\x3b\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x64\x65\x73\x74\x72\x6f\x79\x28\x72\x75\x64\x65\x6c\x79\x29\x7b\x66\x75\x6e\x63\x74\x69\x6f\x6e \x65\x72\x72\x28\x29\x7b\x74\x68\x72\x6f\x77\x27\x54\x68\x69\x73 \x74\x68\x72\x65\x61\x64 \x70\x6f\x6f\x6c \x68\x61\x73 \x62\x65\x65\x6e \x64\x65\x73\x74\x72\x6f\x79\x65\x64\x27\x3b\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x62\x65\x4e\x69\x63\x65\x28\x29\x7b\x69\x66\x28\x71\x2e\x6c\x65\x6e\x67\x74\x68\x29\x7b\x73\x65\x74\x54\x69\x6d\x65\x6f\x75\x74\x28\x62\x65\x4e\x69\x63\x65\x2c\x36\x36\x36\x29\x3b\x7d\n\x65\x6c\x73\x65\x7b\x62\x65\x52\x75\x64\x65\x28\x29\x3b\x7d\x7d\n\x66\x75\x6e\x63\x74\x69\x6f\x6e \x62\x65\x52\x75\x64\x65\x28\x29\x7b\x71\x2e\x6c\x65\x6e\x67\x74\x68\x3d\x30\x3b\x71\x2e\x66\x69\x72\x73\x74\x3d\x6e\x75\x6c\x6c\x3b\x70\x6f\x6f\x6c\x2e\x66\x6f\x72\x45\x61\x63\x68\x28\x66\x75\x6e\x63\x74\x69\x6f\x6e\x28\x76\x2c\x69\x2c\x6f\x29\x7b\x76\x2e\x64\x65\x73\x74\x72\x6f\x79\x28\x29\x3b\x7d\x29\x3b\x70\x6f\x6f\x6c\x4f\x62\x6a\x65\x63\x74\x2e\x65\x76\x61\x6c\x3d\x70\x6f\x6f\x6c\x4f\x62\x6a\x65\x63\x74\x2e\x74\x6f\x74\x61\x6c\x54\x68\x72\x65\x61\x64\x73\x3d\x70\x6f\x6f\x6c\x4f\x62\x6a\x65\x63\x74\x2e\x69\x64\x6c\x65\x54\x68\x72\x65\x61\x64\x73\x3d\x70\x6f\x6f\x6c\x4f\x62\x6a\x65\x63\x74\x2e\x70\x65\x6e\x64\x69\x6e\x67\x4a\x6f\x62\x73\x3d\x70\x6f\x6f\x6c\x4f\x62\x6a\x65\x63\x74\x2e\x64\x65\x73\x74\x72\x6f\x79\x3d\x65\x72\x72\x3b\x7d\n\x72\x75\x64\x65\x6c\x79\x3f\x62\x65\x52\x75\x64\x65\x28\x29\x3a\x62\x65\x4e\x69\x63\x65\x28\x29\x3b\x7d\n\x72\x65\x74\x75\x72\x6e \x70\x6f\x6f\x6c\x4f\x62\x6a\x65\x63\x74\x3b\x7d\x29"; ^ ../src/threads_a_gogo.cc:112:23: warning: ‘typeQueueItem* nuJobQueueItem()’ defined but not used [-Wunused-function] static typeQueueItem* nuJobQueueItem (void) { ^ ../src/threads_a_gogo.cc:125:20: warning: ‘typeThread* isAThread(v8::Handle<v8::Object>)’ defined but not used [-Wunused-function] static typeThread* isAThread (Handle<Object> receiver) { ^ ../src/threads_a_gogo.cc:145:13: warning: ‘void pushToInQueue(typeQueueItem*, typeThread*)’ defined but not used [-Wunused-function] static void pushToInQueue (typeQueueItem* qitem, typeThread* thread) { ^ ../src/threads_a_gogo.cc:182:14: warning: ‘void* aThread(void*)’ defined but not used [-Wunused-function] static void* aThread (void* arg) { ^ ../src/threads_a_gogo.cc:220:22: warning: ‘v8::Handle<v8::Value> threadEmit(const int&)’ declared ‘static’ but never defined [-Wunused-function] static Handle<Value> threadEmit (const Arguments &args); ^ ../src/threads_a_gogo.cc:366:13: warning: ‘void destroyaThread(typeThread*)’ defined but not used [-Wunused-function] static void destroyaThread (typeThread* thread) { ^ make: *** [Release/obj.target/threads_a_gogo/src/threads_a_gogo.o] Error 1 make: Leaving directory/home/node/zgws/web_open/node_modules/threads_a_gogo/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/opt/node-v0.12.0-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.emit (events.js:110:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
gyp ERR! System Linux 3.13.0-32-generic
gyp ERR! command "node" "/opt/node-v0.12.0-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/node/zgws/web_open/node_modules/threads_a_gogo
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok
npm ERR! Linux 3.13.0-32-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "i"
npm ERR! node v0.12.0
npm ERR! npm v2.5.1
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the threads_a_gogo package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls threads_a_gogo
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /home/node/zgws/web_open/npm-debug.log

Installing threads_a_gogo

Installing on node v 0.6.17 , npm 1.1.21 has resulted in the following error

verbose about to build /root/node_modules/threads_a_gogo
info build /root/node_modules/threads_a_gogo
verbose from cache /root/node_modules/threads_a_gogo/package.json
verbose linkStuff [ false, false, false, '/root/node_modules' ]
info linkStuff [email protected]
verbose linkBins [email protected]
verbose linkMans [email protected]
verbose rebuildBundles [email protected]
info install [email protected]
verbose unsafe-perm in lifecycle false
silly exec sh "-c" "node-waf configure install"
silly spawning [ 'sh',
silly spawning [ '-c', 'node-waf configure install' ],
silly spawning '/root/node_modules/threads_a_gogo' ]
info [email protected] Failed to exec install script
info unbuild /root/node_modules/threads_a_gogo
verbose from cache /root/node_modules/threads_a_gogo/package.json
info preuninstall [email protected]
info uninstall [email protected]
verbose unbuild [email protected] [ true, '/root/node_modules', '/root/node_m odules' ]
info postuninstall [email protected]
ERR! [email protected] install: node-waf configure install
ERR! sh "-c" "node-waf configure install" failed with 1
ERR!
ERR! Failed at the [email protected] install script.
ERR! This is most likely a problem with the threads_a_gogo package,
ERR! not with npm itself.
ERR! Tell the author that this fails on your system:
ERR! node-waf configure install
ERR! You can get their info via:
ERR! npm owner ls threads_a_gogo
ERR! There is likely additional logging output above.
ERR!
ERR! System Linux 2.6.18-238.el5
ERR! command "node" "/usr/bin/npm" "install" "threads_a_gogo"
ERR! cwd /root
ERR! node -v v0.6.17
ERR! npm -v 1.1.21
ERR! code ELIFECYCLE
ERR! message [email protected] install: node-waf configure install
ERR! message sh "-c" "node-waf configure install" failed with 1
ERR! errno {}
verbose exit [ 1, true ]

Would it be possible to pass in a function and its arguments "natively" ?

V8 supports the concept of JS function references internally and allows you to "Call" them through the use of the v8::Function class.

Here's a simple module I whipped up to show how this works func_run.cc:

#include <node.h>
#include <v8.h>

using namespace v8;

Handle<Value> Run_It(const Arguments& args) {
  HandleScope scope;

  Function* func = Function::Cast(*args[0]);
  int argc = args.Length() - 1;
  Local<Value> argv[argc];

  for(int i = 0; i < argc; i++) {
    argv[i] = args[i+1];
  }

  Local<Value> result = func->Call(args.This(), argc, argv);

  return scope.Close(result);
}

void init(Handle<Object> target) {
  target->Set(String::NewSymbol("run_it"),FunctionTemplate::New(Run_It)->GetFunction());
}
NODE_MODULE(func_run, init)

And a test script for playing with it test.js:

var func_run = require('./build/Release/func_run');

function myfunc(m,n,o,cb) {
  console.log(m*n+o);
  cb(null,m*n+o);
}

function callback(err,data) {
  console.log("The result should be: "+data);
}

func_run.run_it(myfunc,3,2,7,callback); // Prints:
                                             // 13
                                             // The result should be: 13

func_run.run_it(function(msg) { console.log(msg) }, "API!"); // Prints: 
                                                                  // API!

Basically all it does is run any function you would normally execute in Javascript, but instead executes it through the V8 API. It works for a variable number of arguments passed in, it works with callbacks, it works for any named or anonymous function, and you would get rid of all the string eval'ing and Script::Compiling that's going on in threads_a_gogo currently.

Passing handle to threads

Would it be possible to emulate the same write functionality in child_process and enable sending of handles? In stream_wrap it looks like it just gets the pointer and wraps it as a StreamWrap and then later gets the fd and coverts it to send to the new process. This should be even easier with threads because the thread should be able to easily use the parent's file descriptors, right?

node-gyp rebuild error

Getting this problem when trying to use on OSX 10.10.1 and Node.js 0.12.0

gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info spawn python
gyp info spawn args [ '/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/andrew/workspace/github/Life-Time-Tracker/node_modules/node-threads-a-gogo/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/andrew/.node-gyp/0.12.0/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/andrew/.node-gyp/0.12.0',
gyp info spawn args   '-Dmodule_root_dir=/Users/andrew/workspace/github/Life-Time-Tracker/node_modules/node-threads-a-gogo',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/threads_a_gogo/src/threads_a_gogo.o
../src/threads_a_gogo.cc:34:3: error: unknown type name 'uv_async_t'
  uv_async_t async_watcher; //MUST be the first one
  ^
../src/threads_a_gogo.cc:130:39: error: no member named 'GetPointerFromInternalField' in
      'v8::Object'
      thread= (typeThread*) receiver->GetPointerFromInternalField(0);
                            ~~~~~~~~  ^
../src/threads_a_gogo.cc:159:34: error: unknown type name 'Arguments'; did you mean
      'v8::internal::Arguments'?
static Handle<Value> Puts (const Arguments &args) {
                                 ^~~~~~~~~
                                 v8::internal::Arguments
/Users/andrew/.node-gyp/0.12.0/deps/v8/include/v8.h:127:7: note: 'v8::internal::Arguments'
      declared here
class Arguments;
      ^
../src/threads_a_gogo.cc:162:15: error: calling a protected constructor of class
      'v8::HandleScope'
  HandleScope scope;
              ^
/Users/andrew/.node-gyp/0.12.0/deps/v8/include/v8.h:816:13: note: declared protected here
  V8_INLINE HandleScope() {}
            ^
../src/threads_a_gogo.cc:164:18: error: member access into incomplete type 'const
      v8::internal::Arguments'
  while (i < args.Length()) {
                 ^
/Users/andrew/.node-gyp/0.12.0/deps/v8/include/v8.h:127:7: note: forward declaration of
      'v8::internal::Arguments'
class Arguments;
      ^
../src/threads_a_gogo.cc:165:33: error: type 'const v8::internal::Arguments' does not
      provide a subscript operator
    String::Utf8Value c_str(args[i]);
                            ~~~~^~
../src/threads_a_gogo.cc:172:10: error: no matching function for call to 'Undefined'
  return Undefined();
         ^~~~~~~~~
/Users/andrew/.node-gyp/0.12.0/deps/v8/include/v8.h:305:28: note: candidate function not
      viable: requires single argument 'isolate', but no arguments were provided
  friend Handle<Primitive> Undefined(Isolate* isolate);
                           ^
../src/threads_a_gogo.cc:190:34: error: too few arguments to function call, expected 2, have
      1
  thread->isolate->SetData(thread);
  ~~~~~~~~~~~~~~~~~~~~~~~~       ^
/Users/andrew/.node-gyp/0.12.0/deps/v8/include/v8.h:6642:1: note: 'SetData' declared here
void Isolate::SetData(uint32_t slot, void* data) {
^
../src/threads_a_gogo.cc:220:40: error: unknown type name 'Arguments'; did you mean
      'v8::internal::Arguments'?
static Handle<Value> threadEmit (const Arguments &args);
                                       ^~~~~~~~~
                                       v8::internal::Arguments
/Users/andrew/.node-gyp/0.12.0/deps/v8/include/v8.h:127:7: note: 'v8::internal::Arguments'
      declared here
class Arguments;
      ^
../src/threads_a_gogo.cc:224:33: error: too few arguments to function call, at least
      argument 'isolate' must be specified
  thread->context= Context::New();
                   ~~~~~~~~~~~~ ^
/Users/andrew/.node-gyp/0.12.0/deps/v8/include/v8.h:5263:3: note: 'New' declared here
  static Local<Context> New(
  ^
../src/threads_a_gogo.cc:225:18: error: member reference type 'Persistent<v8::Context>' is
      not a pointer; maybe you meant to use '.'?
  thread->context->Enter();
  ~~~~~~~~~~~~~~~^~
                 .
../src/threads_a_gogo.cc:225:20: error: no member named 'Enter' in
      'v8::Persistent<v8::Context, v8::NonCopyablePersistentTraits<v8::Context> >'
  thread->context->Enter();
  ~~~~~~~~~~~~~~~  ^
../src/threads_a_gogo.cc:228:17: error: calling a protected constructor of class
      'v8::HandleScope'
    HandleScope scope1;
                ^
/Users/andrew/.node-gyp/0.12.0/deps/v8/include/v8.h:816:13: note: declared protected here
  V8_INLINE HandleScope() {}
            ^
../src/threads_a_gogo.cc:230:42: error: member reference type 'Persistent<v8::Context>' is
      not a pointer; maybe you meant to use '.'?
    Local<Object> global= thread->context->Global();
                          ~~~~~~~~~~~~~~~^~
                                         .
../src/threads_a_gogo.cc:230:44: error: no member named 'Global' in
      'v8::Persistent<v8::Context, v8::NonCopyablePersistentTraits<v8::Context> >'
    Local<Object> global= thread->context->Global();
                          ~~~~~~~~~~~~~~~  ^
../src/threads_a_gogo.cc:231:25: error: no member named 'NewSymbol' in 'v8::String'
    global->Set(String::NewSymbol("puts"), FunctionTemplate::New(Puts)->GetFunction());
                ~~~~~~~~^
../src/threads_a_gogo.cc:232:45: error: too few arguments to function call, single argument
      'isolate' was not specified
    Local<Object> threadObject= Object::New();
                                ~~~~~~~~~~~ ^
/Users/andrew/.node-gyp/0.12.0/deps/v8/include/v8.h:2388:3: note: 'New' declared here
  static Local<Object> New(Isolate* isolate);
  ^
../src/threads_a_gogo.cc:233:25: error: no member named 'NewSymbol' in 'v8::String'
    global->Set(String::NewSymbol("thread"), threadObject);
                ~~~~~~~~^
../src/threads_a_gogo.cc:235:31: error: no member named 'NewSymbol' in 'v8::String'
    threadObject->Set(String::NewSymbol("id"), Number::New(thread->id));
                      ~~~~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/threads_a_gogo/src/threads_a_gogo.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:269:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
gyp ERR! System Darwin 14.0.0
gyp ERR! command "node" "/usr/local/bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/andrew/workspace/github/Life-Time-Tracker/node_modules/node-threads-a-gogo
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok

Andrew

Does not work with node version greater than 0.8.9

I have written a small application for testing. I am using Ubuntu 12.10 and it does not work with node versions greater than 0.8.9 . It prints following error

module.js:356
Module._extensions[extension](this, filename);
^
Error: /home/ayeressian/.node_libraries/threads_a_gogo.node: undefined symbol: ev_default_loop_ptr
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/home/ayeressian/Documents/workspace/Fib_bench_thread/fibBench.js:2:17)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:497:10)

Allow to require external node modules in a thread

It is not possible at the moment to require external modules or files from within a thread. I know this is not a bug it is a feature. But it would be much much more helpful if one could use external modules. It is totally obvious to me that this would mean to start up a thread with a bigger context which would also mean a increase in the start-up time for those threads.

Fedora15-x64 - Fail in ex06_jason.js

[root@Fedora15-x64 examples]# node ex06_jason

...../threads_a_gogo/examples/ex06_jason.js:32
if (err) throw err;
^
Error: ReferenceError: builtInObjects is not defined
[root@Fedora15-x64 examples]# node -v
v0.6.14

Error: Cannot find module 'threads_a_gogo'

Hey Guys,

i am not able to install threads_a_gogo.

Node-Version: v0.6.18
v8-version: 3.6.6.25
npm version 1.1.21
Ubuntu-Server 11.04 64bit

i can install from git, but than i dont find the module. tried to change path, also copy into node_modules directory. No Changes

npm install threads_a_gogo doenst work.
Shell Ouput and Debug-Log here:

http://paste.org/49786

synchronization & locks from atomic integers using CAS/TSL

Since you are now enabling multiple threads in the node process, it would be super-cool-wonderful if there was a way to do synchronization using locks, semaphores, mutexes using the atomic Compare-And-Swap and/or Test-and-Set-Lock CPU instructions.

Such lock/increment functionality could be exposed using an interface that is something like Java's AtomicInteger, which enables atomic increment/decrement/set and gets.

test22 and test23 assert errs with libuv

node test22_create_destroy_loop.js ->

Assertion failed: (!uv__is_active(handle)), function uv__finish_close, file ../deps/uv/src/unix/core.c, line 128.
Abort trap

receiving event blocks promise resolution

TAGG: 0.1.13
Node.js: v6.9.5

Check out this strange code:

'use strict'

const tagg = require('threads_a_gogo')

const thread = tagg.create()

const promise = new Promise((resolve) => {
  thread.on('event', resolve)
  thread.eval(`thread.emit('event', 42)`)
})

promise.then(console.log)

// Without this the promise never resolves.
setImmediate(() => {})

If I don't include setImmediate(() => {}) at the end then the promise never resolves and doesn't print 42 to the console. It looks like the main event loop isn't being processed after receiving an event until I kick it with a null setImmediate.

undefined symbol ev_default_loop_ptr

Getting this problem when trying to use on Ubuntu 12.04 and Node.js 0.10.x

vista@dEWDrop:~/www/node/node_modules/threads_a_gogo$ sudo node test/test01_loop_as_fast_as_possible.js 10

module.js:356
Module._extensions[extension](this, filename);
^
Error: /home/vista/.node_libraries/threads_a_gogo.node: undefined symbol: ev_default_loop_ptr
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/home/vista/www/node/node_modules/threads_a_gogo/test/test01_loop_as_fast_as_possible.js:3:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
vista@dEWDrop:~/www/node/node_modules/threads_a_gogo$

any ideas?

Rob

Asynchronous Tasks in Thread

When I was making my first steps with "Threads a Gogo" (which I like very much) I came across a issue that I don't understand:

While this works perfectly fine:

thread.on('myEvent', function cb (data) {
  this.emit('myEventResponse', 'asdf');
});

whereas the answer to the Event never returned in this case:

thread.on('myEvent', function cb (data) {
  setTimeout( function() {
    this.emit('myEventResponse', 'asdf');
  }, 1000 );
});

Are threads not designed to work with asynchronous tasks or am I simply missing something?

Thanks!

[Question] How to use nodejs package in child-thread?

I want to parse HTML in child-thread (need jsdom) because it is much slower than the speed fetching web pages, if I parse in main thread, it will fill up the event loop, cause socket timeout and finally ruin the program.

But jsdom is nodejs package, I can't use global variable jsdom, or declare new variable var jsdom = require('jsdom'); as I do in main-thread,
I also try to pass it to child-thread via parameter, just like thread.eval(fn).eval('fn(jsdom)', cb); and of course, failed.

I have a test on serveral nodejs-defined variable, such as return(typeof(require)); return(typeof(global)); and I get undefined.

I think the child-thread using a completely different context with main-thread, so is it possible to use nodejs package in child-thread?

Or, what's the right way to do this? (Fork, spawn, cluster? or anything better? These three things will make the program much more complex, and what I want to do is just a simple spider.)

Cannot find module 'threads_a_gogo' in linux server

I have tested locally on my mac osx and it worked fine. (installed 0.1.7)

I tried to installing via npm on a dedicated (linux) server and this is what I get:

npm http GET https://registry.npmjs.org/threads_a_gogo
npm http 304 https://registry.npmjs.org/threads_a_gogo
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings

[email protected] install /usr/local/lib/node_modules/threads_a_gogo
node-gyp rebuild

make: Entering directory /usr/local/lib/node_modules/threads_a_gogo/build' CXX(target) Release/obj.target/threads_a_gogo/src/threads_a_gogo.o CC(target) Release/obj.target/threads_a_gogo/src/createPool.js.o ../src/createPool.js.c:1: warning: ‘kCreatePool_js’ defined but not used CC(target) Release/obj.target/threads_a_gogo/src/events.js.o ../src/events.js.c:1: warning: ‘kEvents_js’ defined but not used CC(target) Release/obj.target/threads_a_gogo/src/load.js.o ../src/load.js.c:1: warning: ‘kLoad_js’ defined but not used CC(target) Release/obj.target/threads_a_gogo/src/thread_nextTick.js.o ../src/thread_nextTick.js.c:1: warning: ‘kThread_nextTick_js’ defined but not used SOLINK_MODULE(target) Release/obj.target/threads_a_gogo.node SOLINK_MODULE(target) Release/obj.target/threads_a_gogo.node: Finished COPY Release/threads_a_gogo.node make: Leaving directory/usr/local/lib/node_modules/threads_a_gogo/build'
[email protected] /usr/local/lib/node_modules/threads_a_gogo
└── [email protected]

and then when I try to node tester.js (which just include the lib) I get:
Error: Cannot find module 'threads_a_gogo'

What am I missing here? it also seemed to install a different version (higher than 0.1.7 if I don't specify the specific version)

Thanks,
Guy

Licensing ?

I'd like to contribute with MIT licensed code (restoring compatibility with newer node API, currently broken), but the closed license of thread_a_gogo forbids this. How can we proceed then ?

Function expressions not supported

1st of all great work on this tool. Functions passed to threads only work if they're function declarations. Function expressions like this don't work:

foo = function(x) {
  x = x+1
};

thread.eval(foo).eval("foo(2)");

returns a [Error: ReferenceError: foo is not defined] in the callback

Function definitions in Coffeescript compiles down to javascript expressions instead of declarations so can't be used in coffeescript. Any suggestions?

shared objects

Is their a road map plan for shared objects or ability to pass complex objects or functions from one thread to over ... without using JASON?

The 4th poingt in readme titled Why thread talks about it...

Thanks...

Automatic serialization of parameters

Hi,

In the canonical example, to invoke a function in another thread I'd do: thread.eval('fibo(35)').

It would be really great if when calling thread.eval(fibo), TAGG would automatically add a function to thread called 'fibo', which would take the parameters given, serialize them and pass them to `thread.eval('fibo(serializedparams)')``. This would of course only work with named functions. Usage of TAGG would be much simpler then:

function fibo(n){
  return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
}

function cb(n) { console.log(n); }

var thread= require('threads_a_gogo').create();
thread.eval(fibo);
thread.fibo(35, cb); // executing in another thread!

Is this project still alive?

@xk I am willing to offer long term and active support for this project if that is fine with you.

I'm considering:

  • Refactoring
  • Offering test coverage
  • Providing support for modern node versions
  • Improving performance

threadpool.all.emit() & threadpool.any.emit() only support one 'eventData'

threadpool.all.emit() & threadpool.any.emit() only support one 'eventData', please see the codes below:

function emitAll (event, data) {
pool.forEach(function (v,i,o) {
v.emit(event, data);
});

return poolObject;

}

But in the README, you wrote:
.all.emit( eventType, eventData [, eventData ... ] )


By the way, thank you for creating the 'threads-a-gogo' !
It's useful to me.

Can't install TAGG from npm

Hi,
Just trying to follow install instructions, and failing with npm. Here's the report. Note I'm using node version well above what the ReadMe says is required. I was doing this from within an existing project that has numerous other npm modules. Any thoughts would be appreciated! Would love to give this library a shot.

$ node --version
v6.7.0
$ node-gyp --version
v3.2.0
$ python --version
Python 2.7.9

$ npm install threads_a_gogo

> [email protected] install /Users/blakewest/code/UFC/js/node_modules/threads_a_gogo
> node-gyp rebuild

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
  ACTION *** THREADS_A_GOGO: RUN JS2C src/threads_a_gogo.cc
*** THREADS_A_GOGO: JS2C(kBoot_js): OK
*** THREADS_A_GOGO: JS2C(kPool_js): OK
  TOUCH Release/obj.target/configure.stamp
  CXX(target) Release/obj.target/threads_a_gogo/src/threads_a_gogo.o
../src/threads_a_gogo.cc:136:34: error: unknown type name 'Arguments'; did you mean 'v8::internal::Arguments'?
static Handle<Value> Puts (const Arguments &);
                                 ^~~~~~~~~
                                 v8::internal::Arguments
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:147:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/threads_a_gogo.cc:148:37: error: unknown type name 'Arguments'; did you mean 'v8::internal::Arguments'?
static Handle<Value> Destroy (const Arguments &);
                                    ^~~~~~~~~
                                    v8::internal::Arguments
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:147:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/threads_a_gogo.cc:149:34: error: unknown type name 'Arguments'; did you mean 'v8::internal::Arguments'?
static Handle<Value> Eval (const Arguments &);
                                 ^~~~~~~~~
                                 v8::internal::Arguments
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:147:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/threads_a_gogo.cc:150:34: error: unknown type name 'Arguments'; did you mean 'v8::internal::Arguments'?
static Handle<Value> Load (const Arguments &);
                                 ^~~~~~~~~
                                 v8::internal::Arguments
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:147:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/threads_a_gogo.cc:151:55: error: unknown type name 'Arguments'; did you mean 'v8::internal::Arguments'?
static inline void pushEmitEvent (eventsQueue*, const Arguments &);
                                                      ^~~~~~~~~
                                                      v8::internal::Arguments
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:147:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/threads_a_gogo.cc:152:41: error: unknown type name 'Arguments'; did you mean 'v8::internal::Arguments'?
static Handle<Value> processEmit (const Arguments &);
                                        ^~~~~~~~~
                                        v8::internal::Arguments
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:147:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/threads_a_gogo.cc:153:40: error: unknown type name 'Arguments'; did you mean 'v8::internal::Arguments'?
static Handle<Value> threadEmit (const Arguments &);
                                       ^~~~~~~~~
                                       v8::internal::Arguments
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:147:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/threads_a_gogo.cc:154:36: error: unknown type name 'Arguments'; did you mean 'v8::internal::Arguments'?
static Handle<Value> Create (const Arguments &);
                                   ^~~~~~~~~
                                   v8::internal::Arguments
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:147:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/threads_a_gogo.cc:389:39: error: no member named 'GetPointerFromInternalField' in 'v8::Object'
      thread= (typeThread*) receiver->GetPointerFromInternalField(0);
                            ~~~~~~~~  ^
../src/threads_a_gogo.cc:436:34: error: unknown type name 'Arguments'; did you mean 'v8::internal::Arguments'?
static Handle<Value> Puts (const Arguments &args) {
                                 ^~~~~~~~~
                                 v8::internal::Arguments
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:147:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/threads_a_gogo.cc:438:18: error: member access into incomplete type 'const v8::internal::Arguments'
  while (i < args.Length()) {
                 ^
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:147:7: note: forward declaration of 'v8::internal::Arguments'
class Arguments;
      ^
../src/threads_a_gogo.cc:439:17: error: calling a protected constructor of class 'v8::HandleScope'
    HandleScope scope;
                ^
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:915:13: note: declared protected here
  V8_INLINE HandleScope() {}
            ^
../src/threads_a_gogo.cc:440:33: error: type 'const v8::internal::Arguments' does not provide a subscript operator
    String::Utf8Value c_str(args[i]);
                            ~~~~^~
../src/threads_a_gogo.cc:445:10: error: no matching function for call to 'Undefined'
  return Undefined();
         ^~~~~~~~~
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:324:27: note: candidate function not viable: requires single argument 'isolate', but no arguments were
      provided
  friend Local<Primitive> Undefined(Isolate* isolate);
                          ^
../src/threads_a_gogo.cc:467:33: error: too few arguments to function call, single argument 'params' was not specified
  thread->isolate= Isolate::New();
                   ~~~~~~~~~~~~ ^
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:5650:3: note: 'New' declared here
  static Isolate* New(const CreateParams& params);
  ^
../src/threads_a_gogo.cc:468:34: error: too few arguments to function call, expected 2, have 1
  thread->isolate->SetData(thread);
  ~~~~~~~~~~~~~~~~~~~~~~~~       ^
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:8568:1: note: 'SetData' declared here
void Isolate::SetData(uint32_t slot, void* data) {
^
../src/threads_a_gogo.cc:504:33: error: too few arguments to function call, at least argument 'isolate' must be specified
  thread->context= Context::New();
                   ~~~~~~~~~~~~ ^
/Users/blakewest/.node-gyp/6.7.0/include/node/v8.h:6982:3: note: 'New' declared here
  static Local<Context> New(
  ^
../src/threads_a_gogo.cc:505:18: error: member reference type 'Persistent<v8::Context>' is not a pointer; maybe you meant to use '.'?
  thread->context->Enter();
  ~~~~~~~~~~~~~~~^~
                 .
../src/threads_a_gogo.cc:505:20: error: no member named 'Enter' in 'v8::Persistent<v8::Context, v8::NonCopyablePersistentTraits<v8::Context> >'
  thread->context->Enter();
  ~~~~~~~~~~~~~~~  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/threads_a_gogo/src/threads_a_gogo.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/blakewest/.node/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Darwin 14.5.0
gyp ERR! command "/usr/local/Cellar/node/6.7.0/bin/node" "/Users/blakewest/.node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/blakewest/code/UFC/js/node_modules/threads_a_gogo
gyp ERR! node -v v6.7.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 
npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/Cellar/node/6.7.0/bin/node" "/Users/blakewest/.node/bin/npm" "install" "threads_a_gogo"
npm ERR! node v6.7.0
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the threads_a_gogo package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs threads_a_gogo
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls threads_a_gogo
npm ERR! There is likely additional logging output above.

Node global objects

How about are implementing/passing Node global objects into thread context, for example require(). Do you planning it? It's real? Thanks.

Licensing

Can you please change the license on this to be more open source friendly? I would really appreciate an MIT or MPL style license.

Error: Cannot find module 'threads_a_gogo'

I've read a similar problem from a time ago, but compiling from git doesn't seem to sove the problem. Node version is v0.10.29, was v0.10.26 10 minutes ago and gave the same problems. Will include as much info as possible

I can get the module running on Mac OS X, but on my Linux server it simply won't work.
I've installed node-gyp globally, tried a bunch of stuff, but still get:

module.js:340
throw err;
^
Error: Cannot find module 'threads_a_gogo'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Server. (/home/filip/new-node-t/server.js:6:18)
at Server.emit (events.js:98:17)
at HTTPParser.parser.onIncoming (http.js:2108:12)
at HTTPParser.parserOnHeadersComplete as onHeadersComplete
at Socket.socket.ondata (http.js:1966:22)
at TCP.onread (net.js:527:27)

Tree in node_modules

.
└── threads_a_gogo
├── AUTHORS
├── LICENSE
├── README.md
├── benchmark
│ ├── b00_fibonacci_server_no_threads.js
│ ├── b01_fibonacci_server_threads.js
│ ├── b02_fibonacci_server_threads_pool.js
│ ├── b03_fibonacci_server_clustered.js
│ ├── b04_only_quick.js
│ ├── doubles.c
│ ├── pi.c
│ ├── pi.js
│ ├── pi.rb
│ └── pi_precompiled.js
├── binding.gyp
├── build
│ ├── Makefile
│ ├── Release
│ │ ├── linker.lock
│ │ ├── obj.target
│ │ │ ├── threads_a_gogo
│ │ │ │ └── src
│ │ │ │ ├── createPool.js.o
│ │ │ │ ├── events.js.o
│ │ │ │ ├── load.js.o
│ │ │ │ ├── thread_nextTick.js.o
│ │ │ │ └── threads_a_gogo.o
│ │ │ └── threads_a_gogo.node
│ │ └── threads_a_gogo.node
│ ├── binding.Makefile
│ ├── config.gypi
│ └── threads_a_gogo.target.mk
├── deps
│ └── minifier
│ ├── bin
│ │ └── minify.osx
│ └── src
│ ├── minify.c
│ ├── test
│ ├── test.include.c
│ └── test_minifier.c
├── examples
│ ├── demo.js
│ ├── ex01_basic.js
│ ├── ex01_basic.md
│ ├── ex02_events.js
│ ├── ex02_events.md
│ ├── ex03_ping_pong.js
│ ├── ex03_ping_pong.md
│ ├── ex04_main.js
│ ├── ex04_main.md
│ ├── ex04_worker.js
│ ├── ex04_worker.md
│ ├── ex05_pool.js
│ ├── ex05_pool.md
│ ├── ex06_complex.js
│ ├── ex06_jason.js
│ ├── ex06_jason.md
│ ├── quickIntro_blocking.js
│ ├── quickIntro_evented_childThreadCode.js
│ ├── quickIntro_fiveThreads.js
│ ├── quickIntro_loop.js
│ ├── quickIntro_multiThread.js
│ ├── quickIntro_multiThreadEvented.js
│ ├── quickIntro_oneThread.js
│ └── quickIntro_oneThreadEvented.js
├── lib
│ └── index.js
├── node_modules
│ └── bindings
│ ├── README.md
│ ├── bindings.js
│ └── package.json
├── package.json
├── src
│ ├── createPool.js
│ ├── createPool.js.c
│ ├── events.js
│ ├── events.js.c
│ ├── load.js
│ ├── load.js.c
│ ├── queues_a_gogo.cc
│ ├── thread_nextTick.js
│ ├── thread_nextTick.js.c
│ └── threads_a_gogo.cc
├── test
│ ├── ab.js
│ ├── test00_run_once_and_destroy.js
│ ├── test01_loop_as_fast_as_possible.js
│ ├── test02_loop_as_fast_as_possible.js
│ ├── test03_infiniteLoopFunction.js
│ ├── test04_gc_versus_not_gc.js
│ ├── test05_debugLeaksNoCallbacks.js
│ ├── test06_throw_from_the_thread.js
│ ├── test07_sigkill.js
│ ├── test08_sigkill_leaks.js
│ ├── test09_throw_from_the_callback.js
│ ├── test10_node_nextTick_speed.js
│ ├── test11_multi_callbacks.js
│ ├── test12_precompiled_vs_normal.js
│ ├── test13_thread_nextTick_speed.js
│ ├── test14_emit_once.js
│ ├── test15_emit_ping_pong.js
│ ├── test16_syntax_error_in_the_thread.js
│ ├── test17_pool_pi.js
│ ├── test18_pool_any_as_fast_as_possible.js
│ ├── test19_pool_emit_any_all.js
│ ├── test20_removeAllListeners.js
│ ├── test21_emit_ping_pong_big_string.js
│ ├── test22_create_destroy_loop.js
│ ├── test23_create_destroy_loop.js
│ ├── test24_puts.js
│ ├── test25_delete_puts.js
│ ├── test26_puts_with_many_args.js
│ ├── test27_puts_event_loop.js
│ ├── test28_puts_nextTick_loop.js
│ └── test29_puts_callback_loop.js
└── wscript

Is this repo still actively maintained?

I see some non-trivial PRs and unclosed issues going back a while.

I'm thinking about using this package in a project for work. Wondering how safe of a choice that would be.

Would be grateful if someone could advise!

node v8.9.1 && npm v3.10.10 && v8 4.5 can't be installed

threads_a_gogo.target.mk:108: recipe for target 'Release/obj.target/threads_a_gogo/src/threads_a_gogo.o' failed
make: *** [Release/obj.target/threads_a_gogo/src/threads_a_gogo.o] Error 1
make: Leaving directory '/home/ls/blockchain-explorer/node_modules/threads_a_gogo/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/ls/node-v8.9.1-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Linux 4.4.0-62-generic
gyp ERR! command "/home/ls/node-v8.9.1-linux-x64/bin/node" "/home/ls/node-v8.9.1-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "-v" "rebuild"
gyp ERR! cwd /home/ls/blockchain-explorer/node_modules/threads_a_gogo
gyp ERR! node -v v8.9.1
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok

npm ERR! Linux 4.4.0-62-generic
npm ERR! argv "/home/ls/node-v8.9.1-linux-x64/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v8.9.1
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: node-gyp -v rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp -v rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the threads_a_gogo package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp -v rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs threads_a_gogo
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls threads_a_gogo
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /home/ls/blockchain-explorer/npm-debug.log

../src/threads_a_gogo.cc:346:41: error: ‘class v8::Object’ has no member named ‘GetHiddenValue’
v8::Localv8::Value ptr= receiver->GetHiddenValue(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), "ptr"));

../src/threads_a_gogo.cc:1425:17: error: ‘class v8::Object’ has no member named ‘SetHiddenValue’
nodeObject->SetHiddenValue(v8::String::NewFromUtf8(iso, "ptr"), v8::Number::New(iso, (double) ((uintptr_t) thread)));

precompiled

when i run benchmar/pi_precompiled.js , it said TypeError: Object # has no method 'preCompile'

Cannot build for node 0.7.12-pre

When trying to build the project with node-waf i get the following error:

thomas@ubuntu:~/lajv-node/src/node_modules/threads_a_gogo$ node-waf install
Waf: Entering directory `/home/thomas/lajv-node/src/node_modules/threads_a_gogo/build'

*** Building the project

**** Minifying .js source files
cat /home/thomas/lajv-node/src/node_modules/threads_a_gogo/src/createPool.js | /home/thomas/lajv-node/src/node_modules/threads_a_gogo/deps/minifier/bin/minify kCreatePool_js > /home/thomas/lajv-node/src/node_modules/threads_a_gogo/src/createPool.js.c

cat /home/thomas/lajv-node/src/node_modules/threads_a_gogo/src/events.js | /home/thomas/lajv-node/src/node_modules/threads_a_gogo/deps/minifier/bin/minify kEvents_js > /home/thomas/lajv-node/src/node_modules/threads_a_gogo/src/events.js.c

cat /home/thomas/lajv-node/src/node_modules/threads_a_gogo/src/load.js | /home/thomas/lajv-node/src/node_modules/threads_a_gogo/deps/minifier/bin/minify kLoad_js > /home/thomas/lajv-node/src/node_modules/threads_a_gogo/src/load.js.c

cat /home/thomas/lajv-node/src/node_modules/threads_a_gogo/src/thread_nextTick.js | /home/thomas/lajv-node/src/node_modules/threads_a_gogo/deps/minifier/bin/minify kThread_nextTick_js > /home/thomas/lajv-node/src/node_modules/threads_a_gogo/src/thread_nextTick.js.c

[1/2] cxx: src/threads_a_gogo.cc -> build/Release/src/threads_a_gogo_1.o
../src/threads_a_gogo.cc: In function ‘void* aThread(void*)’:
../src/threads_a_gogo.cc:202:101: error: cannot convert ‘ev_async*’ to ‘ev_loop*’ for argument ‘1’ to ‘void ev_async_send(ev_loop*, ev_async*)’
../src/threads_a_gogo.cc: In function ‘void eventLoop(typeThread*)’:
../src/threads_a_gogo.cc:281:113: error: cannot convert ‘ev_async*’ to ‘ev_loop*’ for argument ‘1’ to ‘void ev_async_send(ev_loop*, ev_async*)’
../src/threads_a_gogo.cc: In function ‘void destroyaThread(typeThread*)’:
../src/threads_a_gogo.cc:362:54: error: cannot convert ‘ev_async*’ to ‘ev_loop*’ for argument ‘1’ to ‘void ev_async_stop(ev_loop*, ev_async*)’
../src/threads_a_gogo.cc:363:25: error: ‘__ev_unref’ was not declared in this scope
../src/threads_a_gogo.cc:363:25: note: suggested alternative:
/usr/local/include/node/ev-emul.h:226:20: note:   ‘node::__ev_unref’
../src/threads_a_gogo.cc: In function ‘void Callback(ev_async*, int)’:
../src/threads_a_gogo.cc:423:62: error: cannot convert ‘ev_async*’ to ‘ev_loop*’ for argument ‘1’ to ‘void ev_async_send(ev_loop*, ev_async*)’
../src/threads_a_gogo.cc: In function ‘v8::Handle threadEmit(const v8::Arguments&)’:
../src/threads_a_gogo.cc:646:101: error: cannot convert ‘ev_async*’ to ‘ev_loop*’ for argument ‘1’ to ‘void ev_async_send(ev_loop*, ev_async*)’
../src/threads_a_gogo.cc: In function ‘v8::Handle Create(const v8::Arguments&)’:
../src/threads_a_gogo.cc:685:5: error: ‘memset’ was not declared in this scope
../src/threads_a_gogo.cc:685:5: note: suggested alternative:
/usr/include/string.h:65:14: note:   ‘node::memset’
../src/threads_a_gogo.cc:685:5: error: invalid conversion from ‘void (*)(ev_async*, int)’ to ‘void (*)(ev_loop*, ev_async*, int)’ [-fpermissive]
../src/threads_a_gogo.cc:686:57: error: cannot convert ‘ev_async*’ to ‘ev_loop*’ for argument ‘1’ to ‘void ev_async_start(ev_loop*, ev_async*)’
../src/threads_a_gogo.cc:687:25: error: ‘__ev_ref’ was not declared in this scope
../src/threads_a_gogo.cc:687:25: note: suggested alternative:
/usr/local/include/node/ev-emul.h:219:20: note:   ‘node::__ev_ref’
Waf: Leaving directory `/home/thomas/lajv-node/src/node_modules/threads_a_gogo/build'
Build failed:  -> task failed (err #1): 
    {task: cxx threads_a_gogo.cc -> threads_a_gogo_1.o}

Terminating a thread

I'm trying to figure out a way how a piece of Javascript code can be forced to terminate its execution. I've tried to use your library like this:

var t = require('threads_a_gogo').create();

var foo = function() {
    while(1) {};
};

t.eval('foo()');

setTimeout(function() {
    t.destroy();
}, 1000);

It doesn't work though. Method does not interrupt what is executing already. Is there a way to achieve this in Javascript?

I know that this task is not really common in node.js programming, but this is absolutely mandatory in my project's needs.

setTimeout

Inside a thread there is no possibility to use setTimeout.

Passing a generic task

I have a generic function (signature: function (fn, obj, cb) {}) that I want to run in a thread then call the cb when it's done. Is this possible in any way? Can it be done with events? Turning the args to strings and passing it in isn't an option.

Windows support

Windows support would be great. I think #24 would help, along with a switch from waf to gyp.

support Instance methods ??

example:

class Test {
constructor() {

}

aaa() {
    return 11111
}

}

const test = new Test()

var numThreads= 10;
var threadPool= require('threads_a_gogo').createPool(numThreads).all.eval(test.aa);

threadPool.all.eval('test.aa()', function cb (err, data) {
process.stdout.write(" ["+ this.id+ "]"+ data);
this.eval('test.aa()', cb);
});

didn't support?

Problem in getting threads-a-gogo from npm

I tried to get threads-a-gogo from npm, but it is not installed well.

It seems that native threads-a-gogo code cannot identify class 'Isolate' in v8.h file.

My environment is Ubuntu 11.10 and gcc 4.6. Other node.js modules are installed well, but this module is not built well.

Please check on this issue.

$ npm install threads_a_gogo

npm http GET https://registry.npmjs.org/threads_a_gogo
npm http 304 https://registry.npmjs.org/threads_a_gogo

> [email protected] install /home/redcarrottt/node_modules/threads_a_gogo
> node-waf configure install


******** THREADS_A_GOGO ********
**** Executing the configuration


Checking for program gcc or cc           : /usr/bin/gcc
Checking for program cpp                 : /usr/bin/cpp
Checking for program ar                  : /usr/bin/ar
Checking for program ranlib              : /usr/bin/ranlib
Checking for program g++ or c++          : /usr/bin/g++
Checking for program ar                  : /usr/bin/ar
Checking for program ranlib              : /usr/bin/ranlib
Checking for g++                         : ok

**** Checking for node_addon

Checking for node path                   : ok /home/redcarrottt/nodejs/working
Checking for node prefix                 : ok /usr

**** Compiling minify.c
gcc /home/redcarrottt/node_modules/threads_a_gogo/deps/minifier/src/minify.c -o /home/redcarrottt/node_modules/threads_a_gogo/deps/minifier/bin/minify

'configure' finished successfully (0.119s)
Waf: Entering directory `/home/redcarrottt/node_modules/threads_a_gogo/build'

*** Building the project

**** Minifying .js source files
cat /home/redcarrottt/node_modules/threads_a_gogo/src/createPool.js | /home/redcarrottt/node_modules/threads_a_gogo/deps/minifier/bin/minify kCreatePool_js > /home/redcarrottt/node_modules/threads_a_gogo/src/createPool.js.c

cat /home/redcarrottt/node_modules/threads_a_gogo/src/events.js | /home/redcarrottt/node_modules/threads_a_gogo/deps/minifier/bin/minify kEvents_js > /home/redcarrottt/node_modules/threads_a_gogo/src/events.js.c

cat /home/redcarrottt/node_modules/threads_a_gogo/src/load.js | /home/redcarrottt/node_modules/threads_a_gogo/deps/minifier/bin/minify kLoad_js > /home/redcarrottt/node_modules/threads_a_gogo/src/load.js.c

cat /home/redcarrottt/node_modules/threads_a_gogo/src/thread_nextTick.js | /home/redcarrottt/node_modules/threads_a_gogo/deps/minifier/bin/minify kThread_nextTick_js > /home/redcarrottt/node_modules/threads_a_gogo/src/thread_nextTick.js.c

[1/2] cxx: src/threads_a_gogo.cc -> build/default/src/threads_a_gogo_1.o
../src/threads_a_gogo.cc:14:0: warning: macro "TAGG_USE_LIBUV" is not used [-Wunused-macros]
../src/threads_a_gogo.cc:50:3: error: ‘Isolate’ does not name a type
../src/threads_a_gogo.cc: In function ‘void* aThread(void*)’:
../src/threads_a_gogo.cc:189:11: error: ‘struct typeThread’ has no member named ‘isolate’
../src/threads_a_gogo.cc:189:20: error: ‘Isolate’ has not been declared
../src/threads_a_gogo.cc:190:11: error: ‘struct typeThread’ has no member named ‘isolate’
../src/threads_a_gogo.cc:194:33: error: ‘struct typeThread’ has no member named ‘isolate’
../src/threads_a_gogo.cc:203:11: error: ‘struct typeThread’ has no member named ‘isolate’
../src/threads_a_gogo.cc:204:11: error: ‘struct typeThread’ has no member named ‘isolate’
../src/threads_a_gogo.cc: In function ‘void eventLoop(typeThread*)’:
../src/threads_a_gogo.cc:223:11: error: ‘struct typeThread’ has no member named ‘isolate’
../src/threads_a_gogo.cc:237:96: error: ‘class v8::Object’ has no member named ‘CallAsFunction’
../src/threads_a_gogo.cc:323:29: error: ‘class v8::Object’ has no member named ‘CallAsFunction’
../src/threads_a_gogo.cc:334:41: error: ‘class v8::Object’ has no member named ‘CallAsFunction’
../src/threads_a_gogo.cc: In function ‘void Callback(ev_loop*, ev_async*, int)’:
../src/threads_a_gogo.cc:435:18: error: ‘class v8::Object’ has no member named ‘CallAsFunction’
../src/threads_a_gogo.cc:480:31: error: ‘class v8::Object’ has no member named ‘CallAsFunction’
../src/threads_a_gogo.cc: In function ‘v8::Handle<v8::Value> threadEmit(const v8::Arguments&)’:
../src/threads_a_gogo.cc:658:37: error: ‘Isolate’ has not been declared
../src/threads_a_gogo.cc: In function ‘v8::Handle<v8::Value> Create(const v8::Arguments&)’:
../src/threads_a_gogo.cc:715:95: error: ‘class v8::Object’ has no member named ‘CallAsFunction’
Waf: Leaving directory `/home/redcarrottt/node_modules/threads_a_gogo/build'
Build failed:  -> task failed (err #1):
        {task: cxx threads_a_gogo.cc -> threads_a_gogo_1.o}
npm ERR! [email protected] install: `node-waf configure install`
npm ERR! `sh "-c" "node-waf configure install"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the threads_a_gogo package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-waf configure install
npm ERR! You can get their info via:
npm ERR!     npm owner ls threads_a_gogo
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.0.0-12-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "threads_a_gogo"
npm ERR! cwd /home/redcarrottt
npm ERR! node -v v0.10.2
npm ERR! npm -v 1.2.15
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/redcarrottt/npm-debug.log
npm ERR! not ok code 0

Problem getting from npm.

I am unable to get threads a gogo by using npm.
The error I am getting:

npm ERR! [email protected] install: node-waf configure install
npm ERR! sh "-c" "node-waf configure install" failed with 127
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the threads_a_gogo package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf configure install
npm ERR! You can get their info via:
npm ERR! npm owner ls threads_a_gogo
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 2.6.32-279.14.1.el6.x86_64
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "threads_a_gogo"
npm ERR! cwd /home/davidslezak/home/nodeProjects
npm ERR! node -v v0.9.11-pre
npm ERR! npm -v 1.2.12
npm ERR! code ELIFECYCLE

Error: Cannot find module 'threads_a_gogo'

Installation with npm ok (no error)

But when I try to launch an example, I have the Cannot find module 'threads_a_gogo' error.

I am on ubuntu 11.10

Here is what I have in my threads_a_gogo module directory:

/usr/lib/node_modules/threads_a_gogo# ls
AUTHORS    build  examples  package.json  src   wscript
benchmark  deps   LICENSE   README.md     test

I should have an index.js or a threads_a_gogo.js file ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.