A cardiologist will primarily diagnose disorders of the heart and treat them with medication. Cardiologists also perform interventions on the arteries in the heart working through puncture wounds in the groin, but they do not do open surgery.
A pulmonologist will diagnose disorders of the lung and treat them with medication. Some pulmonologists will perform interventions through the airway such as bronchoscopy to diagnose some disorders but again, they do not perform open surgery.
Your primary care physician, cardiologist, pulmonologist, or general practitioner may send you to a thoracic surgeon if he/she feels that you could benefit from an operation to treat a condition involving the heart, lungs, esophagus, mediastinum, or chest wall.