The master-slave JK flip-flop is said to solve the problem of racing, as per many online resources that I've referred to.
However, let's say that the initial state of the flip-flop is CLK = 0, J = 0, K = 0 and Q = 0.
Now, K is turned to 1 while CLK is still 0, i.e. in the next clock cycle, the flip-flop will be reset again, even though it is already in the reset state.
As soon as CLK is turned to 1, the master latch will store the value of 0, even though it is already storing 0. But, if the inputs change and J is turned to 1 while CLK is still 1, then the master latch will now store the value of 1.
This behaviour will occur no matter how far apart in time the changes in the inputs are, as long as CLK is equal to 1 for the entire duration.
So, how exactly does the master-slave JK flip-flop solve racing? I understand that the slave latch will not keep fluctuating depending upon the changes in the input, but the value that goes into the slave once CLK turns 0 is still indeterminate.
On the other hand, this problem is solved in an edge-triggered D flip-flop, where if the initial input to the flip-flop stays that way for a long enough time (called the hold time), then after the hold time elapses, the D input may change to any value while the clock is still high and the changes will not be reflected.
So, in this sense, does an edge-triggered D flip-flop do a better job of preventing racing than a master-slave JK flip-flop?