The function of the thoracic cavity is to protect and house vital organs located within it, such as the heart, lungs, and major blood vessels. It provides a protective enclosure for these organs, shielding them from potential injuries or external damage. Additionally, the thoracic cavity helps to maintain a stable environment for the proper functioning of the organs within it by regulating pressure, temperature, and maintaining adequate space for their movements. It also plays a role in respiration by facilitating the expansion and contraction of the lungs during breathing.