我有一个Python程序来创建两个数组,将它们相乘,然后将相乘的结果相加。你知道吗
这是通过过程完成的。你知道吗
如果我创建两个进程,程序将创建两个具有两行两列的数组。
它们应该更改varresultado
的全局值。你知道吗
但是,进程2错误地接收了varresultado
的值,正如您在代码中的注释中看到的那样。你知道吗
可能是什么?你知道吗
程序的某些部分被隐藏了。你知道吗
resultado = []
def multiplicacao(pipe_filho):
if flag:
sem.acquire()
global resultado
# print resultado -->
# Process 1: [] (Correct) ;
# Process 2: [] (Incorrect should be [[47, 6]])
myVar = productMatrix(A[e], B)
resultado += myVar
# print resultado -->
# Process 1: [[47, 6]] (Correct) ;
# Process 2: [[36, 127]] (Correct)
for i in range(len(myVar)):
for j in range(len(myVar[i])):
soma.value += myVar[i][j]
pipe_filho.send(myVar)
if flag:
sem.release()
pipe_filho, pipe_pai = Pipe()
for i in range(2):
e = i
newP = Process(target=multiplicacao, args=(pipe_filho,))
newP.start()
myVar = pipe_pai.recv()
for i in range(2):
newP.join()
# printMatrix(resultado) -->
# | 36 95 | (Incorrect should be | 36 95 36 127 | )
目前没有回答
相关问题 更多 >
编程相关推荐