Kassem, I just did a quick search for this problem and
found it here. The solution is actually pretty simple if you go by the problem description on that page. Don't click that if you want to solve it yourself, there's some code up there.
Think of the table as the shared resource, and synchronize the three processes' access to it. The agent determines which process to signal based on what it places on the table. A smoker locks the table, makes his cigarette and smokes it, then unlocks the table.