Your question is based on a lack of understanding of margin (I'm assuming that you're talking about the U.S.). Let's start with the margin requirement.
If you want to buy shares on margin, under Reg T, the FRB requires 50% of the value of the purchase (brokers can require more). So if you want to buy 100 shares of a $10 stock on full margin then the margin requirement would be $500 and the remaining $500 would be borrowed from the broker at their prevailing margin interest rate.
Under Reg T, the FRB requires 150% of the value of the short sale at the time of sale (brokers can require more) which is the full value of the short sale proceeds plus an additional margin requirement of 50%. So if you want to sell 100 shares of a $10 stock short, the initial margin requirement is $1,500. Effectively, you are posting $500 of collateral.
There is also a minimum margin maintenance requirement for long and short margin positions but let's omit that discussion since it's not germane to your question.
(A) wants to buy the 100 shares at $10. He either uses $1,000 of his cash to buy the shares (fully paid) or he posts $500 margin to buy on 50% margin.
(B) wants to short the shares. If the shares are borrowable, (A)'s broker lends them to (B)'s broker who makes them available for (B) to sell, which he does and $1,000 goes into (B)'s account (slippage and commissions ignored). (B) pays the prevailing borrow rate on the borrowed shares. It accrues daily. The bulk of it goes to (A)'s broker though (B)'s broker may get a piece of the action. (A)'s broker may or may not credit part of the borrow rate to (A).
What happens to (A) and (B) after this depends on the price of the shares and the share availability.
When (A) wants to sell the stock, he does and he repays the borrowed money to his broker (if any). However, (A) only had a book entry in his account for ownership since the actual shares were given to (B) to short sell which he did to (C) who now possesses them.
(B)'s broker must find other replacement shares to borrow either from other in-house accounts or from another broker. If he can't find them, (B) gets a forced buy in notice and must buy the shares on the open market to replace the shares that he borrowed from (A) which were just sold by (A).
Lastly, if (B) is short the shares on an ex-dividend date, he pays the dividend to (A) because (C) owns the actual shares and will receive the dividend.