d*******u 发帖数: 186 | 1 Microsoft onsite multithread synchronization interview question
1. Suppose we have a class:
class Foo {
Public:
A(.....); //if A is called, a new thread will be created and the
corresponding function will be executed.
B(.....); //if B is called, a new thread will be created and the
corresponding function will be executed.
C(.....); //if C is called, a new thread will be created and the
corresponding function will be executed.
......
}
Suppose we have the foll | y*w 发帖数: 238 | 2 不是很明白,有这么确定的顺序的话要多线程干啥
【在 d*******u 的大作中提到】 : Microsoft onsite multithread synchronization interview question : 1. Suppose we have a class: : class Foo { : Public: : A(.....); //if A is called, a new thread will be created and the : corresponding function will be executed. : B(.....); //if B is called, a new thread will be created and the : corresponding function will be executed. : C(.....); //if C is called, a new thread will be created and the : corresponding function will be executed.
| d*******u 发帖数: 186 | 3 As it is stated in the question, when A(or B, or C) is called a new thread
will be created,
so it means that the schedule of A,B,C is up to the OS.
In this case B can be executed first, it is up to the OS.
【在 y*w 的大作中提到】 : 不是很明白,有这么确定的顺序的话要多线程干啥
| e***r 发帖数: 68 | 4 我对多线程没有什么经验,但如果要A,B,C依次运行的话,让A,B,C等三个不同的lock,
程序开始前三个只有LockA开锁,让A完成(或开始)后打开lockB, C完成(或开始)后
打开lockC.
这样可以吗? | l*****c 发帖数: 1153 | 5 works. It is like to implement a token ring.
,
【在 e***r 的大作中提到】 : 我对多线程没有什么经验,但如果要A,B,C依次运行的话,让A,B,C等三个不同的lock, : 程序开始前三个只有LockA开锁,让A完成(或开始)后打开lockB, C完成(或开始)后 : 打开lockC. : 这样可以吗?
| d*******u 发帖数: 186 | 6 it can only work for part A.
【在 l*****c 的大作中提到】 : works. It is like to implement a token ring. : : ,
| e***r 发帖数: 68 | 7 for partB, B开始的时候把A的lock锁起来,然后C开始的时候再把A锁打开。可以吗?
for partC, A开始以后call f.B(),B开始以后Call f.C(),C开始以后Call f.A()?
again,我对线程不是很熟悉,只有模糊印象,高手请解答。 | d*******u 发帖数: 186 | 8 Then it will not work for part A.
【在 e***r 的大作中提到】 : for partB, B开始的时候把A的lock锁起来,然后C开始的时候再把A锁打开。可以吗? : for partC, A开始以后call f.B(),B开始以后Call f.C(),C开始以后Call f.A()? : again,我对线程不是很熟悉,只有模糊印象,高手请解答。
| c******a 发帖数: 600 | 9 题外话,仔细想想,这样用多线程,multi-core的效能等于都浪费了 | e***r 发帖数: 68 | 10 题目没有要求用同一种mechanism满足PartA, B C 吧。
但这样也适用于part A吧,如有错误请指出
【在 d*******u 的大作中提到】 : Then it will not work for part A.
|
|