Skip to content

Instantly share code, notes, and snippets.

@byyam
byyam / coroutine_demo.cpp
Created October 24, 2019 15:06
coroutine cpp
#include <stdio.h>
#include <ucontext.h>
#include <list>
static void one();
static void two();
static void three();
static ucontext_t ctx1;
static ucontext_t ctx2;
@byyam
byyam / pthread_mutex.cpp
Created October 24, 2019 15:07
pthread_mutex
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define NLOOP 5000
pthread_mutex_t counter_mutex = PTHREAD_MUTEX_INITIALIZER;
int counter;
@byyam
byyam / pthread_producer_consumer.cpp
Created October 24, 2019 15:08
pthread_producer_consumer
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
struct msg {
struct msg *next;
int num;
};
@byyam
byyam / pthread_semaphore.cpp
Created October 24, 2019 15:09
pthread_semaphore
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <semaphore.h>
#define NUM 5
int queue[NUM];
sem_t blank_number, product_number;
@byyam
byyam / fifo_cache.cpp
Created October 24, 2019 15:11
fifo cache demo
#include "fifo_cache.hpp"
tFifoCache::~tFifoCache()
{
if (p_cache_buffer != reinterpret_cast<char *>(-1))
{
int nRet = ::shmdt(p_cache_buffer);
if (0 != nRet)
{
@byyam
byyam / workdays.go
Last active May 29, 2025 10:48
get workdays
package workdays
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"time"