A police officer talks with a boy at the memorial at Dallas police headquarters on Friday. (Laura Buckman/Agence France-Presse via Getty Images)

Seth Stoughton is a law professor at the University of South Carolina and a former police officer and investigator. Follow him on Twitter @PoliceLawProf.

The vivid, horrifying videos of Philando Castile and Alton Sterling dying at the hands of police officers have brought new attention to fatal police shootings. The terrifying ambush that took the lives of five Dallas police officers and wounded seven others has brought new attention to attacks on the police.

And so, I am afraid. Not of the violence itself. Even considering recent high-profile events and heightened attention to police shootings, violence both by and against police officers remains relatively rare and has been in decline for years. But I am afraid of the impact these events will have on the already-strained relationship between police and the communities they serve.

Those effects are perhaps most visible in the significant tensions that exist between the Black Lives Matter movement and the Blue Lives Matter movement. Despite their very different perspectives, participants in both movements have essentially the same concern: a perception that society does not value members of their community. Attempts to discredit that perception or demonstrate that it is exaggerated or inaccurate have proved counterproductive. Perception becomes reality.

Both communities feel embattled and victimized. Both are angry. The sad truth of the matter is that there are good reasons for both to feel the way they do. Meanwhile, the consequences of this mistrust are draining and pernicious.

The safety of officers and civilians alike depends, in large part, on the strength of the relationship between the police and the public. Public distrust of the police can decrease cooperation with law enforcement, which can, in turn, lead to an increase in violent crime and resistance. Police distrust of the public, in turn, can lead to an increase in officer misconduct and the use of force, as well as the adoption of aggressive, “zero tolerance” tactics that further exacerbate the tension, perpetuating a downward spiral.

Distrust can have even more immediate effects. In the aftermath of the Michael Brown shooting in Ferguson, Mo., many people in the local community and across the country rejected the official version of events: that Brown was shot while aggressively moving toward an officer he had already assaulted. Instead, they believed that Brown was shot while surrendering, with his hands up.

Why, in the face of two conflicting stories, didn’t they credit the official version? The answer has very little to do with the shooting itself and everything to do with trust. The official story was rejected — even after an extensive Justice Department investigation supported it — because people did not trust the police.

The fractured relationship between the local police and the community ultimately endangered hundreds of officers and thousands of civilians, resulting in millions of dollars of damage. This is nothing new. Half of the 10 most violent and destructive riots in U.S. history were responses to perceived police abuses.

Further, while policing in the United States is primarily a local affair, police-community relationships are not. Police shootings, especially in the age of the Internet and viral video, echo far beyond the communities where they take place. The death of Sterling in Louisiana and Castile in Minnesota, reinforcing the perception that law enforcement too often views black men as presumptively dangerous and black lives as cheap, gave rise to protests across the country.

The same is true when officers are shot. The attack that took the lives of five Dallas officers will haunt police, buttressing the perception that they are besieged by a hostile populace.

I’m afraid that incidents such as those of the past several days will reinforce a view that violence is not only justified but appropriate. That such incidents will drive police and the communities they serve further apart, dampening any interest in reconciliation.

But I’m also optimistic. Even relationships that have been undermined by a long history of distrust and anger can be repaired. We have seen some remarkable progress in truly challenging situations, including police departments in Richmond, Calif., and Camden, N.J., just to name a few.

We can learn from those successes, and from successes outside the United States. In Northern Ireland, for example, police and the Irish Republican Army were in a state approaching open warfare for years before establishing a tentative, then more lasting, relationship in the late 1990s. More recently, U.S. military personnel put community policing principles into practice with great effect in counterinsurgency operations in Iraq and Afghanistan.

If positive relationships can be established or repaired in those environments, surely we can do the same in the context of domestic policing. Surely we must.