Changchun Master Li

one form to understand Hamming weight 一个表理解汉明重量

algorithm

There are three solutions to calculate hamming weight.

bruce force

1
2
3
4
5
6
7
8
int hammingWeight(uint32_t n) {
int count = 0;
while(n != 0) {
count += n %2;
n = n /2;
}
return count;
}
Read more

Python异步队列实现生产者消费者模式

Python

background

进程间通信方式又称IPC,可以分为控制信息的通信(如semophore、signal)和数据信息的通信(如pipe、message queue、shared memory、socket)。IPC通常由操作系统完成。

同一进程的线程共享全局变量和内存,所以线程间通信简单。操作系统的最小调度单位是线程,线程的花费也小得多。但线程为了保护共享变量,需要做好同步/互斥。线程间的同步方式有临界区、互斥锁、信号量。

由Python有GIL的存在,多线程只适用于IO密集型程序。
Python有很多异步的library,如multiprocessing、threading、gevent。

Read more
Prev Next