During chemical bonding, elements tend to fill up their valece shell octets.
In CO2, the central atom, C satisfies its octet by sharing 2 pairs of electrons from two oxygen atoms, in addition to its own valence electrons.
Similarly, in F2O, NH3 and O2, valnce shell octet of al the elements are fulfilled. But not all stable molecules can have that criterion fulfilled. CO is an example. Here, carbon can share at most two electrons from the oxygen atom, thus totalling (4+2)=6 valence electros in its outertmost shell, while octet of oxygen atom is achieved in the process. So, it is an octet deficient stable molecule.
However, the concept of three electron two centre bond can somehow explain its bonding, albeit in the light of a different concept, where it is assumed that two of the three electrons are contributed by oxygen, and one by carbon.