Skip to content

Instantly share code, notes, and snippets.

View tkil's full-sized avatar

Anthony Foiani tkil

View GitHub Profile
@tkil
tkil / vector-swap-demo.cpp
Created July 12, 2013 15:10
threaded vector swapping...
/*
Compile line for native build:
PATH=/usr/local/gcc/bin:$PATH \
g++ -O3 -std=c++11 -o vector-swap-demo vector-swap-demo.cpp \
-I/usr/local/boost/include \
-pthread -lboost_thread-mt -lpthread -lrt
Compile line for cross build:
@tkil
tkil / linux-lists.c
Created July 11, 2013 01:30
quick demo of using linux list primitives in a userspace program
#include <stdio.h>
#include <stdlib.h>
/***************************** stddef.h *****************************/
/* (not really, this is cribbed from gcc info pages...) */
#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
/***************************** kernel.h *****************************/
/*
Compiling this code gives me a warning about old-style casts:
$ g++ -Wold-style-cast -o g++-warnings-check g++-warnings-check.cpp -lz
g++-warnings-check.cpp: In function ‘int main()’:
g++-warnings-check.cpp:49:20: warning: use of old-style cast [-Wold-style-cast]
"deflateInit" is actually a macro:

typical output:

$ make -f semaphore.make demo
./semaphore-boost
./semaphore-boost: 10 threads * 100000 reps = 1000000 total; elapsed = 6833 milliseconds
./semaphore-mutex
./semaphore-mutex: 10 threads * 100000 reps = 1000000 total; elapsed = 160 milliseconds
./semaphore-pthread
./semaphore-pthread: 10 threads * 100000 reps = 1000000 total; elapsed = 150 milliseconds
@tkil
tkil / xlib-delay-required.c
Created October 22, 2012 03:34
Xlib seems to require a delay after GC creation.
/* compile line: gcc -o test xlib-delay-required.c -lX11 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <X11/Xlib.h>
int
main(int argc, char* argv[])