由买买提看人间百态

topics

全部话题 - 话题: semaphore
首页 上页 1 2 3 4 5 6 7 8 9 下页 末页 (共9页)
x****o
发帖数: 21566
1
1) semaphore has two types: counting semaphore and binary semaphore
2) mutex is similar to binary semaphore but with one biggest difference
"the principle of ownership"
Mutex requires ownership, semaphore does not.
That's it.
w********p
发帖数: 948
2
来自主题: JobHunting版 - failed bloomberg phone interview
我正好有两道题的答案,其余的我想好后在一起讨论吧
Difference between MUTEX and Semaphore
"A mutex is a binary semaphore, usually including extra features like
ownership or priority inversion protection. The differences between mutexes
and semaphores are operating system dependent. Mutexes are meant to be used
for mutual exclusion only and binary semaphores are meant to be used for
event notification and mutual exclusion."
Mutex:
Is a key to a toilet. One person can have the key - occupy the toilet - at
the time. When fi
f**********t
发帖数: 1001
3
感觉大概思路好像是这样的:
对于每个Car, 它需要等待两个资源。一个是绿灯。另一个是前面的车所占的位置。绿
灯可看作一个mutex, 前面的车所占的位置可看作一个semaphore。每个车得先拿到
mutex, 再拿到semaphore,才能前进。并且每个车拿到的semaphore和release的
semaphore不一样。
不知这题有比较好的解答么?另外还有没有啥比较好的多线程设计题?在学习中。
s********k
发帖数: 6180
4
spin lock和mutex相比,前者busy waiting,后者可能被context switch出去,跟hold
时间长短没关系,spin lock用得不好一样hold时间长,造成很大的性能损失。但是有
些时候你急需lock,比如很多系统里面的维护heartbeat什么,mutex不如spin lock快。
mutex和semaphore,很多人都会说一个是binary,一个可以是any number,但是这个其
实不是根本区别。mutex只能被获取它的process/thread释放,而semaphore可以被其他
的process/thread释放(经常在embedded里面比如某个timer interrupt建立或者释放
semaphore然后其余thread去access,用来保证某个时间段里面某种资源最多被调用多
少次)。所以mutex应该说是用在mutual exclusion,而semaphore多用在sync
c*****a
发帖数: 808
5
来自主题: JobHunting版 - two functons and two threads
这样对不对啊
Semaphore A;
Semaphore B;
init(){
A = new Semaphore(){
...
};
B = new Semaphore(){
...
};
A.acquire();
B.acquire();
}
gofirst(){
A.release()
}
gosecond(){
A.acquire();
A.release();
...
B.release();
}
cc150有这题
a***o
发帖数: 1182
6
来自主题: JobHunting版 - 新鲜电面经
就是它用的这种semaphore应该是加不上去就停了,等待空出的时候吧
比如你看他的void lockRead() { semaphore++; },就是如果semaphore现在已经是32(
最大值)的话,就应该等到31的时候再加吧?
所以在lockWrite里面一直加semaphore,加不上去的时候应该是要挺得
还有个问题就是这个代码里面unlockWrite也没有unlock &mutex
感觉这个代码问题还是不少
o********n
发帖数: 193
7
来自主题: JobHunting版 - 新鲜电面经
你说的都对,除了倒数第二行。mutex解锁在acquire semaphore后立马做了,但是既然
semaphore已被writer全部占用,另一个writer也进不来,所以代码没错。当然,如果
你不封装writer lock ,用C直接acquire /release writer lock,你把release押后也
是可以的。
"所以在lockWrite里面一直加semaphore,加不上去的时候应该是要挺得"
Write的时候,要把semaphore收回,有些reader已经release了,所以立马收回,有些
正在reading,那就wait了,但不是busy waiting。这个你觉得有问题吗^_^
a********9
发帖数: 129
8
来自主题: JobHunting版 - google, vmware 面经
google面的是SRE
电面是国人大哥,一些c语言的pointer问题,然后一道leetcode原题
onsite1:
1)combination,还是没dupliate的,要把结果保存起来,我说用linked list,因为是
用c写,还要自己implement linkedlist, 略坑爹
2) 就是很简单的统计两个string分别有多少个单独的letter
onsite2:
bst inorder iterator
onsite3:
一个文件,每行是rack_name + machine id,输出每个rack有多少个machine,按大小排
序,我是先扫一遍存hashtable,再存进linkedlist再sort,这回没让我实现hashtable
跟linkedlist了,不过要我把用过的api单独再declear一下,最后再写个mergesort
onsite4:
有很多个machine,要求检测哪些die了,要求parallel,就写了一个for loop创建若干
个thread来执行任务,有点thread pool的感觉,用一个array来表示哪个machine被检... 阅读全帖
c*******7
发帖数: 438
9
来自主题: JobHunting版 - 想问一下那道H2O的多线程题
题目是这样的:实现两个函数: H() and O(), 这两个函数会被多线程调用。如果满足
当前2个线程调用H(),和1个线程调用O(),让以上3个线程返回,产生一个水分子(可能
是HHO,HOH,OHH)。调用H()的当前线程不能大于2,调用O()的当前线程不能大于1。
我思前想后,写了一个,请大家帮忙看看。(排版有问题,tab改成下划线了。。。)
(发现前面写的好像不太对,又改了一次)
private Object mutex = new Object;
private Semaphore hSemaphore = new Semaphore(2);
private Semaphore oSemaphore = new Semaphore(1);
private int hCount;
private int oCount;
public void H() {
____hSemaphore.acquire();
____processH();
____
____synchronize(mutex) {
________hCount++;
________if(oCount == 1... 阅读全帖
l*****a
发帖数: 14598
10
来自主题: JobHunting版 - 求问一道multithreading问题
Semaphore sem1=new Semaphore(1);
Semaphore sem2=new Semaphore(0);
void functionFoo() {
while(1){
sem1.acquire();
System.out.print("Foo");
sem2.release();
}
}
void functionBar() {
while(1) {
sem2.acquire();
System.out.print("Bar");
sem1.release();
}
}
L*****1
发帖数: 34
11
来自主题: JobHunting版 - 问一道multithreading的题
被问过一道一样的题目,不过是foo和bar,转一个大神的解答:
Semaphore sem1=new Semaphore(1);
Semaphore sem2=new Semaphore(0); //only when permit number is bigger
than 0
void functionFoo() {
while(1){
sem1.acquire();
System.out.print("Foo");
sem2.release();
}
}
void functionBar() {
while(1) {
sem2.acquire();
System.out.print("Bar");
sem1.release();
}
}
sem2=0 确保一上来block
sem1=1 确保第一次不会block
require就是-1
release就是+1
t*****a
发帖数: 106
12
来自主题: JobHunting版 - 请教L家生成H2O水分子的题。
加mutex是对的,不好意思,看错了。开始想着用while+wait能按顺序输出HHO,发现不
行。写了个code,贴在这
public class H2O {
private Lock lock;
private Semaphore semH;
private Semaphore semO;
H2O()
{
lock=new ReentrantLock();
semH=new Semaphore(0);
semO=new Semaphore(0);
}
public void H() throws InterruptedException
{
semH.release();
semO.acquire();
System.out.println("H");
}
public void O() throws InterruptedException
{
lock.lock();
semH.acquire();
semH.acquire();
lock.unlock();
semO.release();
semO.release();
System.out.println("O");
}
... 阅读全帖
h******e
发帖数: 52
13
来自主题: JobHunting版 - g 家面经
简化一下
public class ProducerConsumer
{
private Semaphore fillCount;
private Semaphore emptyCount;
private ConcurrentQueue queue;
public ProducerConsumer()
{
fillCount = new Semaphore(0, 100);
emptyCount = new Semaphore(100, 100);
queue = ConcurrentQueue();
}
public void Producer()
{
while(true)
{
//produce something
int x = 1;
... 阅读全帖
p*****d
发帖数: 81
14
来自主题: Working版 - 离职时给当前雇主的交接时间

谢谢!
请教谈不上,我们互相学习 :)
semaphore 允许多于一个线程在critical section, mutex 只允许一个线程进入
critical section;基本上mutex就是binary semaphore;所以semaphore并不是on/off
flag,而是一个广义的counter。我个人经验,mutex更灵活,lock/unlock总是匹配,
更易推导thread的interaction,(binary)semaphore有一些subtle的问题,所以我只
用mutex。
b***i
发帖数: 3043
15
程序生成了一个类似dos的窗口,等待用户输入。
主程序用了一个循环,里面等待semaphore,这个semaphore是窗口部分的KeyPressed里
面released
我的窗口部分keypressed, keyreleased, keytyped都重写了。在一个1.7G CPU的电脑
上,没有问题,是eclipse来编译运行。然后load到网上成为applet,在2.2G 双核的电
脑上,运行快了。但是,如果连续按下Enter, 会出现几个换行后,死机。体现在等待
semaphore,但是我看到打印的信息,最后semaphore等待的时候,keypressed根本没有
进入。为什么按下一个键却没有进入
keypressed?
public void keyPressed(KeyEvent e){
DEBUG("-->");
keypressed= e.getKeyCode();
if (keymode==3){
switch(keypressed){
case KeyEvent.VK_Enter:
z***e
发帖数: 5393
16
来自主题: Programming版 - question about the read/write locker
It seems the semaphore is used to block readers.
so for "semaphore++", if semaphore reaches maxReaders, the instruction will
be blocked. That's why lockWrite() just set the semaphore to the max value
so no other reader thread will enter.
for multiple writes, it's protected by:
QMutexLocker locker(&mutex);
S**I
发帖数: 15689
17
来自主题: JobHunting版 - [合集] 面经+一点个人体会
☆─────────────────────────────────────☆
yuhanlin (Yuhan) 于 (Mon Aug 29 00:18:17 2011, 美东) 提到:
周五面完最后一个onsite, 累的惨兮兮的, 好容易爬回家. 不管结果如何, 这段时间找
工作算是告一段落了.
下面把这段时间面试中被问到的题目整理一下, 供大家参考. 我也就不说具体是那些公
司了, 都是很典型的面试题, 到哪里都有可能会被问到.
* implement memcpy? How to improve? how to determine if a system is
32bit or 64bit?
* how is static keyword used in Java?
* a list of intervals, no overlapping and sorted, write a function to
insert an interval into the list and still keep the list sorted and no
overlapping.... 阅读全帖
a********d
发帖数: 195
18
来自主题: JobHunting版 - 某start-up on-site 小感
这个还真没用过,看了看感觉区别据说是这样:
CountDownLatch是一组线程等待所有的线程都结束或者计数结束。
semaphore控制同时对资源访问的数量。
问题是semaphore上下浮动,如何控制说一个write过来了,控制semaphore数量直到0?
额外的mutex还是啥?迷糊了已经。
S*******e
发帖数: 379
19
来自主题: JobHunting版 - LI面试题: 实现Blocking Queue
在C++里是不是就用两个semaphore?
Semaphore size = 0;
semaphore mutex = 1;
void push(T d){
mutex.P();
push(d);
mutex.V();
size.V()
}
T pop() {
size.P();
mutex.P();
T d = pop();
mutex.V();
return d;
}
m*****n
发帖数: 204
20
来自主题: JobHunting版 - Java编程讨论:LinkedIn的H2O
package test;
import java.util.concurrent.Semaphore;
import test.IElements.WaterElements;
public class H2OExtraThread {
private final Semaphore sema = new Semaphore(0);

private volatile boolean isRunning = true;

// Called by the control thread
private void controllerRun() {

while (isRunning) {
try {
sema.acquire(WaterElements.totalAtomsPerMolecule);
} catch (InterruptedException e) {
continue;
... 阅读全帖
m*****n
发帖数: 204
21
来自主题: JobHunting版 - Java编程讨论:LinkedIn的H2O
package test;
import java.util.concurrent.Semaphore;
import test.IElements.WaterElements;
public class H2OExtraThread {
private final Semaphore sema = new Semaphore(0);

private volatile boolean isRunning = true;

// Called by the control thread
private void controllerRun() {

while (isRunning) {
try {
sema.acquire(WaterElements.totalAtomsPerMolecule);
} catch (InterruptedException e) {
continue;
... 阅读全帖
m**n
发帖数: 384
22
修改后,这段代码对了
可是,我在多进程编程,多个子进程共同合作打印这个乘法表
需要用到semaphore,就是那些sem_wait, sem_post
如果在父进程里,设定这个semaphore,那每个子进程就可以直接拿来用了
可是现在问题是,main()函数里父进程并未设定这个semaphore,
该如何是好
b*s
发帖数: 82482
23
这个早就有了,wiki还提出了古希腊的例子。关键是对方要论证现代西方所用的
semaphore 系统是inspired by中国儿戏,这个就很牵强。
Modern design of semaphores was first foreseen by the English scientist
Robert Hooke, who first gave a vivid and comprehensive outline of visual
telegraphy to the Royal Society in a submission dated 1684 in which he
outlined many practical details. The system (motivated by military concerns,
following the recent Battle of Vienna in 1683) was never put into practice.
(wiki)
如果要论证西方的semaphore系统源自中国儿戏,那么Robert Hooke至少要见过这种儿
... 阅读全帖
e*******t
发帖数: 7
24
新的Darwin是不错,但是有几个问题是我在开放中发现的:
1) Darwin的开放文档很难查。如果你想要man 个命令的话,你发现
机器上装的文当有些是不全和不兼容的。比如,当你用Semaphore时,
它只支持BSD和一些Posix的APIs,有些还不对,比如你man sem_open,
然后看SEE ALSO Section,然后依次去man 他们,你会发现有些根本
没有。再比如你可以去/usr/include/sys/semaphore.h去查哪些APIs
可以用,你会发现sem_destroy()根本没有man,但是你用了他,编译
不出错,说明在.h中有声明,而且库中有目标码。
2) 网上可供讨论的forum很少,我只看到apple自己有个Darwin开放
站点讨论组和有关的资料库,但是当我要查我想查的问题,在search
一栏输入我的keywords, 结果不是一堆垃圾,就是傻也没有。
3) 如果你不小心,有leftover留在系统中,特别是IPC资源(message
queue, semaphore, FIFO, shared memory, etc.),那你的麻烦就来了
k********r
发帖数: 18
25
来自主题: Programming版 - about critical section
请教difference between critical section, mutex and semaphore:
critical section a block of codes which requires atomic operation.
mutex and semaphore 是用来实现 critical section的。
就这关系把?
我以前一直以为 mutex and semaphore 是用来限制 resource,
critical section 是用来限制行动的, 感觉理解有误。
h*********s
发帖数: 5
26
来自主题: Programming版 - about critical section
mutex and semaphore 可以用来保护critical section的
我对mutex and semaphore 实现不清楚,觉得mutex象是binary semaphore
l*****c
发帖数: 1153
27
来自主题: Programming版 - 给大家出个多进程的题
OK. I know what you mean. That works. Where is your complete solution? But I
think we only need one semaphore to count the # of consumers, no need to be
one semaphore per consumer.
I have a solution with three semaphores (but I left it at home).

destroy
T*****9
发帖数: 2484
28
来自主题: Programming版 - multi-thread 一问,
use lock or semaphore
可以用buffer,然后对这个buffer用2个semaphore,1个lock或者3个semaphore
你可以看看pthread,同时我觉得fifo的实现基本是1读1写(事实上是多读多写),你可
以看看他的实现
b***y
发帖数: 2799
29
来自主题: Programming版 - 精华区翻出来的MS老题,thread safe
Maybe my answer upstairs misled you.
mutex is just a binary semaphore. The only difference is that semaphore
controls several resources whereas mutex controls only one.
As of waiting or returning after detecting a locked mutex, it depends on the
user of the mutex, not the mutex or semaphore itself.
It's like you go to a public restroom and find all the toilets are occupied.
It's up to you to just wait there or go tell your dad. It doesn't matter
how many toilets there, one or many, they are al
h**********l
发帖数: 410
30
来自主题: Programming版 - 一道多线程的面试题 (转载)
这是我的第一想法,但是有没有可能thread还没run到wait,main thread就notify了,我
的第二想法是用counting semaphore array, 第一个initialize成1, 后面的都
initialize成0, 然后每个thread先P()自己的semaphore, print word, 然后V()下一个
semaphore,我觉得这样比较保险一些

a
W***o
发帖数: 6519
31
我是这么理解的,用一个通俗的“排队上厕所大便"的例子来说一下我的体会:
1. Mutex:
一queue人排队等着去厕所大便,但是只有一个厕所,所以只能FIFO,一个人拿到钥匙
以后,如厕,锁门;这个时候后面所有的人都不能进去,必须要等前面的那个人大便完
开门以后,拿到钥匙才能进去如厕,锁门....
2. Semaphore:
还是一queue人排队等着去厕所大便,这个时候有3个厕所(不分男女假设),都需要钥
匙进去;钥匙都一样,这个需要有人告诉大家有几把钥匙available, 如果是0,那大家
耐心等。如果有1个钥匙,前面的一个人进去大便,如果有3把钥匙,一次放前面三个人
去厕所。
我只写过mutex, 但是看过semaphore 的实现代码,觉得差不多就是这意思,
连续两次RELEASE, mutex 可能就交换好两次钥匙了
semaphore 肯定就是放两个人进去大便了
请大牛赐教
c******n
发帖数: 4965
32
来自主题: Unix版 - [转载] two programming questions
【 以下文字转载自 Linux 讨论区 】
【 原文由 creation 所发表 】
in semaphore, if I want to use the semaphore between processes
I have to put the semaphore in shared memory
i.e.
for sem_init(sem_t *sem,.....)
the #sem# has to be in shared mem
but I can't tell malloc to allocate a #sem# in
a particular region,
neither can I tell shmat() to attach to an existing
real memory region (i.e.
sem=malloc()
shmat(shm_id, sem,...)
)
so how can i do this?
(2) in open('filename', O_XXXX, S_IRUSR) , the S_IRUSR flag,
where does
H*M
发帖数: 1268
33
来自主题: JobHunting版 - failed bloomberg phone interview
Thanks for sharing!
It is strange that bloomberg cares so much about network programming.
I think what you ansewered is good.
just a few things.
Q: what is difference between semaphore and mutex?
a: semaphore is for multi-processes and mutex is for multi-threads
This is not correct ba.

,
multiple
r****o
发帖数: 1950
34
来自主题: JobHunting版 - bloomberg电面,攒rp求bless
弱弱的问一下,mutex, conditional variable, semaphore这些东西是不是
是对线程间同步和进程间同步都适用?

semaphore.
j**l
发帖数: 2911
35
来自主题: JobHunting版 - 人生中第一次面试
好像是这样。然后semaphore是mutex的推广,mutex类似binary semaphore
r******d
发帖数: 308
36
来自主题: JobHunting版 - multi thread复习请教
http://www.cc.gatech.edu/classes/AY2000/cs6210_spring/pthreads_tutorial.htm
在这个链接里面把synchronization分成
mutex / semaphore / condition variable (monitor) / rwlocks
http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html#SYNCHRONIZATION
在这个链接里面把synchronization分成
mutex / joins / condition variable
所以可能本来就没有标准答案, 把知道的都写上去好了, 呵呵, 下次问到我就写
linux 的 synchronization包括
mutex / semaphore / condition variable (monitor) / joins / rwlocks
哈哈, 不过怀疑 monitor是不是java的一个概念? 因为我在pthread里面找不到, 还要
学习一下monitor
b*****n
发帖数: 760
37
来自主题: JobHunting版 - G面经
1. You have a class that supports to input sample records and to compute the
average of the samples. The class has two members: total and count. How
would you make the class thread-safe? If 99% of the time average() is called
, how to optimize for that?
2. Talk about your recent interesting project/bug.
3. You have 100 files, each containing 10G sorted integers. How to merge all
integers into one sorted file?
4. Write a function to reverse digits of an integer. E.g. 123 --> 321, -890
--> -98.
5.... 阅读全帖
S*******0
发帖数: 198
38
来自主题: JobHunting版 - Bloomberg电面面经
刚记起还有一道题,问
Does C++ allow multiple inheritance?
What is the potential problem of multiple inheritance?
就说了说继承的ambiguity,举了个例子
class A
class B,C : public A
class D :public B,C
问:怎么解决?
用virtual inheritance: class B,C : virtual public A
B,C共享基类A
----
下午刚面完,说下周一给结果。
大部分是概念题,和behavior题
Why bloomberg?
Why software developer?
Describe the case that you feel press from colleague
How do you manage projects?
1. Ask a C++ project. Describe what features of c++ are used?
Explain encapsulatoin, inheritance, ... 阅读全帖
S**I
发帖数: 15689
39
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
S**I
发帖数: 15689
40
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
d********w
发帖数: 363
41
来自主题: JobHunting版 - [teradata面经] hadoop engineer
1. smart pointer implementation
2. thread safe hashmap, how to improve concurrency, I said to read/write
lock, use many locks to reduce 粒度, each lock cover one part of range of
buckets.
3. stack implementation, use array
4. insert node into linkedlist
5. LRU cache, getItem if not hit cache, should visit database to fetch that.
HashTable + DoubleLinkedlist
6. fib
7. implement spin lock, test and set 原语,
8. 32/64 alignment pading,
struct s{
char a;
int b;
void* c
long long d;
}
sizeof(s) in 32b... 阅读全帖
d********w
发帖数: 363
42
来自主题: JobHunting版 - [teradata面经] hadoop engineer
1. smart pointer implementation
2. thread safe hashmap, how to improve concurrency, I said to read/write
lock, use many locks to reduce 粒度, each lock cover one part of range of
buckets.
3. stack implementation, use array
4. insert node into linkedlist
5. LRU cache, getItem if not hit cache, should visit database to fetch that.
HashTable + DoubleLinkedlist
6. fib
7. implement spin lock, test and set 原语,
8. 32/64 alignment pading,
struct s{
char a;
int b;
void* c
long long d;
}
sizeof(s) in 32b... 阅读全帖
g*********e
发帖数: 14401
43
来自主题: JobHunting版 - 献上最近两家onsite面经(长!)
最近onsite了两家公司,没有签NDA,今天把面经回忆整理下献上。很长,希望对大家
有所帮助。特别是EE的同学。
Qualcomm QCT HW
先是去QCOM candidate caring center。这里会见到HR,然后问些何时毕业,VISA的问
题。还会告诉你如何打车在不同building之间走。不爽的是HR会在这里问SALARY
expectation,我说expect market price,a competitive number blabla。
HR非要问what it means? 我没办法:you want a number? HR:yes. 我想了5秒:
10w?
HR 脸色一变,开始压价:10w是非常高的数字,这样对其他老员工不公平。
我说这个数字很reasonable啊?HR问你真的不想改了吗?反复问is it a make or a
break? 我最后说9w5。然后说是flexible的,Q的福利好也是优势blabla.
之后HR态度就很冷淡了,问问题也不怎么responsive。
之后是technical面经,有些问题记不起来了
亚裔MM:
... 阅读全帖
a********d
发帖数: 195
44
来自主题: JobHunting版 - 某start-up on-site 小感
呵呵,轻喷,学习了。
看了楼下贴的链接,发现好像是没有让read都要等待write lock,而是一个write lock
放mutex,然后开始一个一个收semaphore,收到满然后执行write后semaphore全放掉。
这样省了read去看write lock。不知道理解对不对,望指正。

read
r****s
发帖数: 1025
45
来自主题: JobHunting版 - 某start-up on-site 小感

lock
read 不需要看mutex吗?
另外semaphore没有一个一个的说法,semaphore里有permit。
y****1
发帖数: 58
46
spinlock 和 semaphore, mutex 的 区别????
可是感觉没有回答到点上。
spinlock: 1,hold lock 时间短,2,busy wait, 中断里用
semaphore 和 mutex: 1, hold lock 时间长, 2,block wait,中断里不可用
不知道还有其他吗??
谢谢!!
m**********0
发帖数: 356
47
Here is what I found:
spinlock:
It is a big CPU sucker and its biggest risk is being interrupted by OS
scheduler while holding the lock.
One needs to be very careful during implementation to reduce unnecessary
busy waiting
In general, works only with hardware atomic support such as test-and-set
mutex: resource can be accessed only by 1 at a time
semaphore: # of accessors to the resource at a time depending on the
initialization of the semaphore. When it is initialized to 1, it has same
effect as... 阅读全帖
w**********2
发帖数: 20
48
来自主题: JobHunting版 - G家 system design 和 open ended questions
大家好,5天前,hc 送审的时候, 纠结通过率,搜到了这个网站,(这网站在新加坡
貌似没什么人用) 相见恨晚。。 3天前,写了onsite 小面筋,想求个祝福。可惜新注
册的用户,禁言三天,没有发上来。三天后,hc 的结果出来了, 还要加一轮。不管机
率如何, 既然还有希望,准备拼一枪。
“our profile was actually reviewed at our hiring committee in the US this
morning and I just received the results. The committee has actually decided
they need some additional data through a couple more interviews.
Accordingly, I'd like to set up 2 more interviews for you, these interviews
will be focused on system design and open ended questions.”
看了版上... 阅读全帖
w**********2
发帖数: 20
49
来自主题: JobHunting版 - G家 system design 和 open ended questions
大家好,5天前,hc 送审的时候, 纠结通过率,搜到了这个网站,(这网站在新加坡
貌似没什么人用) 相见恨晚。。 3天前,写了onsite 小面筋,想求个祝福。可惜新注
册的用户,禁言三天,没有发上来。三天后,hc 的结果出来了, 还要加一轮。不管机
率如何, 既然还有希望,准备拼一枪。
“our profile was actually reviewed at our hiring committee in the US this
morning and I just received the results. The committee has actually decided
they need some additional data through a couple more interviews.
Accordingly, I'd like to set up 2 more interviews for you, these interviews
will be focused on system design and open ended questions.”
看了版上... 阅读全帖
l*********u
发帖数: 19053
50
来自主题: JobHunting版 - two functons and two threads
用semaphore
哪位给说说,俺thread用的不多,理解的对不对:
semaphore像个on/off flag,mutex lock/unlock是锁门/开门。
首页 上页 1 2 3 4 5 6 7 8 9 下页 末页 (共9页)