Considering weapon retention training and individual awareness, if the officer becomes aware of the threat before the first grab or strike, he can attempt to gain reaction space and use his training to difuse or subdue. Should it escalate, he may deploy whatever force necessary up to and including deadly force. If the threat is only recognized once the assailant grabs the weapon then it comes down to execution of training and attempting to gain the advantage. Any attem,pt to assault a police officer is deemed a deadly encounter because there is always at least one firearm involved.

There are a number of things to consider here. We receive a fair bit of training on this, as you might imagine. The first line of defense is situational awareness and basic precautions when dealing with suspects. As well, there are intangibles like confidence, psychological control, officer appearance and fitness.... We have been told that as a result of interviews of inmates who have attacked officers that they very consciously "size up" the copper and decide if they can take him.
If the officer is sloppy, inattentive, overweight... They feel they have a pretty good chance.
As well, there are subtle clues as to an impending attack that we are trained to recognize.
We've all (LEOs that is...) been shown video of such attacks; there are several that have been taken by squad-car video.
Usually the officer makes mistakes.

Should such an attack actually occur (very rare, BTW) the defensive tactics employed are fairly straightforward; hold the weapon in the holster while trying to disable/dislodge the attacker. Not easy...
Usually the guy is down low and hunched over... Not much to hit.
I carry a knife weak-side, one of those little fixed-blade K-bar TDI models. So do many of my colleagues.
I'm also well-trained in simple defensive techniques like the 'sprawl".... If a guy comes in low he's most likely ending up with his face in the dirt and a Glock lined up.

And i wondered if you were getting out your car after responding to reports of a suspicious young man in the area when you suddenly saw the chap walk up to you in a threatening way and attempt to grab your piece?

Very simply, I would do whatever it took to retain control of my weapon. As previously stated in this thread, there is only one reason that an assailant would attempt to disarm a police officer. Regarding a person "visually targeting" my weapon/other items on my belt, or stepping towards/cutting an angle towards my weapon side, I adjust my stance accordingly and VERY assertively warn the person to cease those behavior(s).

A guy I knew from high school became an LA County Sheriff, where you have to start in the jails first then he went to the street. He wanted a cushier job so he became Newport Beach cop later. His first call is suspect fleeing house after break in. He told me he was rushing there on foot, and ran in to, literally, the suspect and they both collided and fell down and start wrestling. He felt the guy was going for his gun so he grabs his Maglight, which he learned from LA County Sheriffs, and starts bashing the guy in the forehead and splits it open blood spurting and all kinds of fun stuff. He arrests the guy and then when all is over his CO says, Mike this ain't LA you can't do that **** in Newport you will get in a lot of trouble. I would venture some other LEO's do similar, maybe they can chime in?