Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
char **ptr; /* global */
/* thread routine */
void *thread(void *vargp)
{
int64_t myid = (int64_t)vargp;
@mosfet1kg
mosfet1kg / sema.c
Created July 2, 2015 12:10
semaphore
#include <semaphore.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
@mosfet1kg
mosfet1kg / race.c
Created July 3, 2015 02:40
thread race condition
#include <semaphore.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
@mosfet1kg
mosfet1kg / func.js
Created July 28, 2015 19:11
함수 호출
var Q = require('q');
(function(){
Q.fcall(function(){
return Q.all([
(function(){
var d = Q.defer();
d.resolve('hi');
console.log('test1');
@mosfet1kg
mosfet1kg / q_paralell.js
Created July 29, 2015 07:13
npm Q parallel excution
var Q = require('q');
Q.fcall([
(function(){
setTimeout(function(){
console.log('func1');
},5000)
})(),
(function(){
setTimeout(function(){
@mosfet1kg
mosfet1kg / callback.js
Created July 31, 2015 06:33
callback pattern
function a(v1,v2, callback1) {
console.log(v1, v2);
callback1(7,8,function(){console.log('hi');});
}
a(5, 6, a);
@mosfet1kg
mosfet1kg / Q_sequence.js
Created July 31, 2015 06:43
Q sequence
var result = Q();
func.push(function(){
var d = Q.defer();
d.resolve('a');
return d.promise;
});
func.push(function(){
console.log(arguments);
@mosfet1kg
mosfet1kg / Q_parallel2.js
Created July 31, 2015 07:36
Q parallel2.js
var Q = require('q');
var func = [];
func.push(function (){
var d = Q.defer();
d.resolve('a');
console.log('a');
return d.promise;
@mosfet1kg
mosfet1kg / Q_closure.js
Created July 31, 2015 10:10
Q + Closure
var Q = require('q');
var funcs = [];
for (var i = 0; i < 3; i++) {
funcs.push((function(m){
return function() {
var d = Q.defer();
@mosfet1kg
mosfet1kg / async_waterfall_in_parallel.js
Created July 31, 2015 16:02
async_waterfall_in_parallel
var async = require('async');
var products = ['a', 'b', 'c', 'd', 'e'];
var funcs = [];
products.forEach(function(item){
funcs.push(
function(callback){
async.waterfall([