Skip to content

Instantly share code, notes, and snippets.

View cutlassfish's full-sized avatar

cutlassfish

  • Yokohama-shi, Kanagawa, Japan
View GitHub Profile
#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <stdint.h>
double mul(double x, double y) {       
return x * y;
}
const int page_size = 1024 * 4;
char buf[page_size] __attribute__((aligned(page_size))) // (1)                 
SUBDIRS := subdir0 subdir1
TARGET  := $(addprefix test_,$(SUBDIRS))
.PHONY: test
.PHONY: $(TARGET)
test:       
$(MAKE) -k $(TARGET)
$(TARGET):      
$(MAKE) -C $(subst test_,,$@) test
.PHONY: test
test:
$(MAKE) -C subdir0 test
$(MAKE) -C subdir1 test
.PHONY: test
test:
for d in $(SUBDIRS); do \
$(MAKE) -C $$d test; \
done
#include <string>
#include <iostream>
#include <thread>
#include <chrono>
#include <mutex>
class Helper
{
public:
void handle(std::string filepath,
#include <mutex>
std::mutex mutex;
int main()
{
while (!mutex.try_lock()) {
// ロックを取得できなかった際の処理(イベントループを回すなど)
}
// ロックが必要な処理.
#include <regex>
#include <vector>
#include <algorithm>
#include <iostream>
int main()
{
std::string str("ABC,DEF,GHI,JKL");
std::regex pattern(",");
std::sregex_token_iterator begin(str.begin(), str.end(), pattern, -1);
#include <regex>
#include <algorithm>
#include <iostream>
int main()
{
std::string str("version 1.20.300.400");
std::regex pattern("([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)");
{
std::sregex_token_iterator begin(str.begin(), str.end(), pattern, {1,3});
#include <chrono>
#include <iostream>
int main()
{
ThreadPool tp(5, 1000);
for (int n = 0; n < 1000; n++) {
auto workA = [ ] { std::cout << "WorkA" << std::endl; };
auto workB = [=] { std::cout << "WorkB n=" << n << std::endl; };
#include <deque>
#include <vector>
#include <functional>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <cassert>
template <typename T> class Queue
{