Skip to content

Instantly share code, notes, and snippets.

@gnitnaw
gnitnaw / thread_cpu.c
Created October 23, 2016 10:05
Example to limit the cpu affinity
#include <stdlib.h>
#include <stdatomic.h>
#define __USE_GNU
#include <sched.h>
#include <pthread.h>
typedef struct {
char name[16];
int sleepTime;
} Node;
@gnitnaw
gnitnaw / thread.c
Last active October 19, 2016 12:39
gcc thread.c -Wall -pedantic -O3 -std=gnu11 -o thread -lpthread
#include <stdio.h>
#include <stdatomic.h>
#include <pthread.h>
typedef struct {
char name[16];
int sleepTime;
} Node;
void _usleep(int);
@gnitnaw
gnitnaw / sort.c
Created June 18, 2016 18:58
merge sort
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define NDATA 100000
void swap(uint32_t* );
uint32_t** sepaTwo(uint32_t*, uint32_t);
uint32_t* mergeTwo(uint32_t*, uint32_t, uint32_t*, uint32_t);
uint32_t* mergeSort(uint32_t*, uint32_t);
@gnitnaw
gnitnaw / DeepC_example_4.c
Created March 29, 2016 19:03
DeepC -- example 4
#include <stdio.h>
Struct X {int a; char b; int c;};
int main(void) {
printf("%zd\n", sizeof(int));
printf("%zd\n", sizeof(char));
printf("%zd\n", sizeof(struct X));
}
@gnitnaw
gnitnaw / DeepC_example_3.c
Created March 29, 2016 18:15
DeepC -- example 3
#include <stdio.h>
void foo(void)
{
int a;
printf("%d\n", a);
}
void bar(void)
{
@gnitnaw
gnitnaw / DeepC_example_2.c
Created March 29, 2016 16:53
Deep C -- example 2
#include <stdio.h>
void foo(void)
{
int a;
++a;
printf("%d\n", a);
}
int main(void)
@gnitnaw
gnitnaw / DeepC_example_1.c
Last active March 30, 2016 07:43
Deep C -- example 1
int main()
{
int a = 42;
printf("%d\n", a);
}
@gnitnaw
gnitnaw / cond.c
Created November 3, 2015 14:24
Example of pthread_cond_wait
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <time.h>
#include <unistd.h>
#include <sys/mman.h>
#define NLOOP 30
int global_thread = 0;
pthread_mutex_t mutex;
@gnitnaw
gnitnaw / mpu6050.dts
Created July 20, 2015 14:25
Device tree overlay for mpu6050
// Definitions for MPU6050
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2708";
fragment@0 {
target = <&i2c1>;
__overlay__ {
@gnitnaw
gnitnaw / mcp320x.dts
Last active November 5, 2015 17:38
Device tree overlay for mcp3008
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708";
/* disable spi-dev for spi0.0 */
fragment@0 {
target = <&spi0>;
__overlay__ {
status = "okay";