我正在做一个学期末的专题,我需要能够把一个矩阵的幂次,我需要使问题多线程。在
此代码在某些情况下有效,而在其他情况下则不行。我相信这与process_data函数中嵌套循环的逻辑有关,但我不确定我做错了什么!我已经为这个工作了几个星期了,我完全被难住了。这似乎与我的线程越界有关,但即使如此,我也不太确定,因为有些情况下线程超出了界限,但仍然正确地计算矩阵。在
请帮忙!在import copy
import numpy
import Queue
import random
import threading
import time
import timeit
# Create variable that determines the number of columns and
# rows in the matrix.
n = 4
# Create variable that determines the power we are taking the
# matrix to.
p = 2
# Create variable that determines the number of threads we are
# using.
t = 2
# Create an exit flag.
exitFlag = 0
# Create threading class.
class myThread (threading.Thread):
def __init__(self, threadID, name, q):
t