The operating system has a subsystem called "messages" to tell applications about things such as mouse clicks. Every time you click on the application, the OS drops a message* in the app's queue. When the app is ready it reads the messages off the queue and decides what to do.
Windows can't really tell what your application is doing, but it can see whether or not the app is reading the messages or just letting them pile up. So if no messages are pulled for 5 seconds, Windows throws up the "not responding" screen. The rest of the 316 clicks are just stuffing the message mailbox to the brim.
Linux is mostly very similar, except the UI stuff is not a part of the core OS, and there are several different systems.
On Windows a mouse click is actually two messages: "button pressed" followed by "button released".
"The definition of insanity is doing the same thing over and over again and expecting different results" except frustratingly this actually does work when half the time the solution to technical issues is turning on/off, uninstalling/reinstalling, restarting, or reloading the program. So I guess nowadays the definition of insanity is "doing the same thing over and over again for a period longer than 30 minutes before googling to see if anyone else has had the same problem"
My coworkers do this when any program takes longer than 1 second. Frequently spam clicking on a button that does something, so they end up with 14 copies of whatever they were trying to print or the program opening 14 times
This reminds me of a good lesson my uni IT/video shooting & editing teacher often said: "Your problem is not about what the computer does, it's what you clicked it to do. Stop. Think for a momenent."