The math is really weird.
OK, working with the textbook example here. Let's start with cottage town, where every tile has 2

. The 15 pop working the city have all brought there own lunch, so there is a +2 surplus. We'll set the food bar at 49/50, and happy cap the city at 15, so the next point of growth is unhappy. That many people in the city, let's assume there is a granary on hand.
Turn 0
City A has 15 citizens working the tiles. The foodbar is filled with 1

overflow. The city grows to 16 citizens, and the newcomer is unhappy about that. The foodbar refills to 26/52, and the city is now stagnant.
City B hires 13 specialists. This leaves 2 citizens working the tiles - the total food yield is 6, against a hunger of 30, so the foodbar drops to 25/50
Turn 1
City A has 2 citizens working the tiles - the total food yield is 6, against a hunger of 32, so the foodbar drops to 0/50. 2 working citizens and one unhappy leave 13 specialists.
City B hires 13 specialists. This leaves 2 citizens working the tiles - the total food yield is 6, against a hunger of 30, so the foodbar drops to 1/50
Turn 2
City A hires 15 specialists - the total food yield is 2, against a hunger of 32. The unhappy citizens abandons the city. The foodbar drops to 0/50.
City B hires 1 specialist, and sends everybody else back to work. 14 citizens in the fields yield 30 food and the city is stagnant.
Final Tally
City A - 28 specialist turns, 0/50 food.
City B - 27 specialist turns, 1/50 food.
BUT....
This is really a lucky accident - a consequence of the overly simplistic model. Suppose that instead of every tile being +2

, the city had a +4

tile and two +1

tiles (so that the total yield of the worked tiles is the same). This means that each city can hire one more specialist per turn...
Whoops, on turn 0 City A can't hire any specialists, because there's no food to spare when growing. And on turn 2 City A can't hire more specialists, because the remaining population is unhappy. So City A loses that race, and still falls 1 food short.
Somebody else can muck about with other combinations, my notes are getting really twisted up.
Trading the "free" food in the granary for something useful is a reasonable play, but I wouldn't choose to starve the city unless there were no other options (such as whipping multiple items).