atomic

面试:Zookeeper常见11个连环炮

試著忘記壹切 提交于 2021-02-12 13:03:04
面试的时候,面试官只要看到你简历的上写的有Zookeeper(熟悉、掌握)之类,那你至少要准备接下来的11连问。 NO1:说说zookeeper是什么? ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现(Chubby是不开源的),它是集群的管理者,监视着集群中各个节点的状态根据节点提交的反馈进行下一步合理操作。最终,将简单易用的接口和性能高效、功能稳定的系统提供给用户 。 Zookeeper一个最常用的使用场景就是用于担任服务生产者和服务消费者的注册中心,服务生产者将自己提供的服务注册到Zookeeper中心,服务的消费者在进行服务调用的时候先到Zookeeper中查找服务,获取到服务生产者的详细信息之后,再去调用服务生产者的内容与数据,简单示例图如下: NO2:了解Zookeeper的系统架构吗? Zoo Keeper 的架构图中我们需要了解和掌握的主要有: (1)ZooKeeper分为服务器端(Server) 和客户端(Client),客户端可以连接到整个 ZooKeeper服务的任意服务器上(除非 leaderServes 参数被显式设置, leader 不允许接受客户端连接)。 (2)客户端使用并维护一个 TCP 连接,通过这个连接发送请求、接受响应、获取观察的事件以及发送心跳。如果这个 TCP 连接中断

How to execute atomic write in CUDA?

旧街凉风 提交于 2021-02-11 09:26:40
问题 First of all I cannot find reliable source whether the write is atomic in CUDA or not. For example Is global memory write considered atomic in CUDA? touches this subject but the last remark shows we are not talking about same atomic notion. Having the code: global_mem[0] = pick_at_random_from(1, 2); shared_mem[0] = pick_at_random_from(1, 2); executed by gazillion of threads "atomic" means in both cases the content will be 1 or 2 and it is guaranteed nothing else can show up (like 3). Atomic

How to execute atomic write in CUDA?

喜夏-厌秋 提交于 2021-02-11 09:26:26
问题 First of all I cannot find reliable source whether the write is atomic in CUDA or not. For example Is global memory write considered atomic in CUDA? touches this subject but the last remark shows we are not talking about same atomic notion. Having the code: global_mem[0] = pick_at_random_from(1, 2); shared_mem[0] = pick_at_random_from(1, 2); executed by gazillion of threads "atomic" means in both cases the content will be 1 or 2 and it is guaranteed nothing else can show up (like 3). Atomic

How to execute atomic write in CUDA?

老子叫甜甜 提交于 2021-02-11 09:24:20
问题 First of all I cannot find reliable source whether the write is atomic in CUDA or not. For example Is global memory write considered atomic in CUDA? touches this subject but the last remark shows we are not talking about same atomic notion. Having the code: global_mem[0] = pick_at_random_from(1, 2); shared_mem[0] = pick_at_random_from(1, 2); executed by gazillion of threads "atomic" means in both cases the content will be 1 or 2 and it is guaranteed nothing else can show up (like 3). Atomic

does the atomic instruction involve the kernel

我是研究僧i 提交于 2021-02-11 07:05:54
问题 I'm reading this link to learn about futex of Linux. Here is something that I don't understand. In order to acquire the lock, an atomic test-and-set instruction (such as cmpxchg()) can be used to test for 0 and set to 1. In this case, the locking thread acquires the lock without involving the kernel (and the kernel has no knowledge that this futex exists). When the next thread attempts to acquire the lock, the test for zero will fail and the kernel needs to be involved. I don't quite

does the atomic instruction involve the kernel

六眼飞鱼酱① 提交于 2021-02-11 07:05:49
问题 I'm reading this link to learn about futex of Linux. Here is something that I don't understand. In order to acquire the lock, an atomic test-and-set instruction (such as cmpxchg()) can be used to test for 0 and set to 1. In this case, the locking thread acquires the lock without involving the kernel (and the kernel has no knowledge that this futex exists). When the next thread attempts to acquire the lock, the test for zero will fail and the kernel needs to be involved. I don't quite

does the atomic instruction involve the kernel

三世轮回 提交于 2021-02-11 07:04:45
问题 I'm reading this link to learn about futex of Linux. Here is something that I don't understand. In order to acquire the lock, an atomic test-and-set instruction (such as cmpxchg()) can be used to test for 0 and set to 1. In this case, the locking thread acquires the lock without involving the kernel (and the kernel has no knowledge that this futex exists). When the next thread attempts to acquire the lock, the test for zero will fail and the kernel needs to be involved. I don't quite

golang sync包

十年热恋 提交于 2021-02-11 02:33:31
sync 在golang 文档上,golang不希望通过共享内存来进行进程间的协同操作,而是通过channel的方式来进行,当然,golang也提供了共享内存,锁等机制进行协同操作的包; 互斥锁: Mutex 和 RWMutex var m *sync.RWMutex m = new(sync.RWMutex) go m.RLock() // read var m.Unlock() go m.Lock() // write var m.Unlock() 多个goroutine都需要做一个操作,但是这个操作只需要执行一次即可,这就需要Once var once sync.Once for i :=0; i<10; i++{ go func(){ once.Do(func_val) } } 此时多个goroutine只执行一次; WaitGroup 和Cond 一个goroutine等待其他多个goroutine执行完毕之后才能继续执行,则这种多协程等待问题需要用WaitGroup wp := new(sync.WaitGroup) wp.add(10) for i:=0; i<10; i++{ go func(){ fmt.Println("Done, i=", i) wp.Done() }() } wp.Wait() sync.Cond用来控制某个条件下

How correctly wake up process inside interrupt handlers

一个人想着一个人 提交于 2021-02-10 07:14:00
问题 Briefly, in a read method i check if a variable is 0 and if it's i put the current process to sleep: static ssize_t soc2e_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) { ... struct soc2e_dev *soc2e = (struct soc2e_dev *)filp->private_data; if (soc2e->bytes == 0) { if (wait_event_interruptible(soc2e->wlist, (soc2e->bytes > 0))) return -ERESTARTSYS; } ... } I must wake up the process in an interrupt handler: static irqreturn_t soc2e_irq_handler(int irq, void *dev) { ...

How correctly wake up process inside interrupt handlers

假装没事ソ 提交于 2021-02-10 07:12:27
问题 Briefly, in a read method i check if a variable is 0 and if it's i put the current process to sleep: static ssize_t soc2e_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) { ... struct soc2e_dev *soc2e = (struct soc2e_dev *)filp->private_data; if (soc2e->bytes == 0) { if (wait_event_interruptible(soc2e->wlist, (soc2e->bytes > 0))) return -ERESTARTSYS; } ... } I must wake up the process in an interrupt handler: static irqreturn_t soc2e_irq_handler(int irq, void *dev) { ...