Commit 621e27f2 authored by Julian Frosch's avatar Julian Frosch
Browse files

Added some stuff for multi-threading

parent 835bab94
# THIS BRANCH IS ONLY FOR TESTING AND DEMONSTRATION OF MULTICORE-USE!
# BezLinApp for node.js and electron
This is an application written with node.js and electron that tries to do a piecewise linear approximation on Bezier curves in a given SVG-file.
......
......@@ -6,9 +6,6 @@
</head>
<body>
<h1>Hello World!</h1>
We are using node <script>document.write(process.versions.node)</script>,
Chrome <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
<div id="svgHolder" class="holder">
Drag your svg-file here!
......
......@@ -7,6 +7,29 @@ $(function(){
svgHolder.ondragleave = svgHolder.ondragend = function () {
return false;
};
/*
Here, we try some things with multiple processes:
*/
var fork = require('child_process').fork;
// get this machine's number of CPUs
var numCPUs = require("os").cpus().length;
console.log("Number of cores: " + numCPUs);
// create one child for every core
var children = [];
for (var i = 0; i < numCPUs; i++) {
// fork-command takes the foreign script, arguments and further options as params
children[i] = fork('./js/thread_test/thread.js', [i]);
// listen on messages from the children, print info and kill it
children[i].on('message', function(m) {
var child_id = m.c_id;
console.log("Got message from child " + child_id);
children[child_id].kill();
});
}
// When the user drops the file
svgHolder.ondrop = function (e) {
e.preventDefault();
......@@ -29,5 +52,13 @@ $(function(){
}
});
/*
More cool multi-core-stuff!
Send a message to every child. Each child will send something back, which
results in the parent killing it.
*/
children.forEach(function(child) {
child.send({content: "do something!"});
});
};
});
var id = process.argv[2];
console.log("Child " + id + " started!");
process.on('message', function(m) {
// child got message
console.log("Child " + id + " got message: " + m.content);
process.send({c_id: id, content: "success"});
})
......@@ -3,7 +3,7 @@ const app = electron.app; // Module to control application life.
const BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
// Report crashes to our server.
electron.crashReporter.start();
//electron.crashReporter.start();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
......@@ -30,6 +30,9 @@ app.on('ready', function() {
// Open the DevTools.
mainWindow.webContents.openDevTools();
// example: Access arguments
console.dir(process.argv);
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment