从顺序到并发和并行
第十五课
int main() {
int numAgents = 10;
int numTickets = 150;
for (int agent = 1; agent <= numAgents; agent++) {
SellTickets(agent, numTickets/numAgents);
}
return 0;
}
void SellTickets (int agentID, int numTicketsToSell) {
while (numTicketsToSell > 0) {
printf("Agent %d sells a ticket \n", agentID);
numTicketsToSell--;
}
printf("agent %d: All done \n", agentID);
}Last updated