synchronization or semaphores to be specific

hi there, i'm trying to understand the concept of threads and synchronization by this put together code but it's weirdly printing chefs preparing meals before customers even ordering? can i have help on the code or be given resources how to fix it atleast? this is the output for reference
[Arrival] Customer 4 arrives.
[Arrival] Customer 2 arrives.
[Seating] Customer 4 is seated.
[Arrival] Customer 1 arrives.
[Seating] Customer 1 is seated.
[Seating] Customer 2 is seated.
[Arrival] Customer 3 arrives.
[Seating] Customer 3 is seated.
[Preparation] Chef starts preparing meal for Customer 1
[Preparation] Chef starts preparing meal for Customer 4
[Order] Customer 4 placed an order: Salad
[Order] Customer 1 placed an order: Burger
[Order] Customer 3 placed an order: Pasta
[Order] Customer 2 placed an order: Pizza
[Departure] Customer 4 finishes eating and leaves.
[Departure] Customer 3 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Departure] Customer 2 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Departure] Customer 1 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Table Availability] Table is now available for other customers.
[Serving] Meal for Customer 4 is served.
[Meal Ready] Meal for Customer 4 is ready for serving.
[Preparation] Chef starts preparing meal for Customer 3
[Meal Ready] Meal for Customer 1 is ready for serving.
[Serving] Meal for Customer 1 is served.
[Preparation] Chef starts preparing meal for Customer 2
[Meal Ready] Meal for Customer 3 is ready for serving.
[Serving] Meal for Customer 3 is served.
[Meal Ready] Meal for Customer 2 is ready for serving.
[Serving] Meal for Customer 2 is served.
[Arrival] Customer 4 arrives.
[Arrival] Customer 2 arrives.
[Seating] Customer 4 is seated.
[Arrival] Customer 1 arrives.
[Seating] Customer 1 is seated.
[Seating] Customer 2 is seated.
[Arrival] Customer 3 arrives.
[Seating] Customer 3 is seated.
[Preparation] Chef starts preparing meal for Customer 1
[Preparation] Chef starts preparing meal for Customer 4
[Order] Customer 4 placed an order: Salad
[Order] Customer 1 placed an order: Burger
[Order] Customer 3 placed an order: Pasta
[Order] Customer 2 placed an order: Pizza
[Departure] Customer 4 finishes eating and leaves.
[Departure] Customer 3 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Departure] Customer 2 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Departure] Customer 1 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Table Availability] Table is now available for other customers.
[Serving] Meal for Customer 4 is served.
[Meal Ready] Meal for Customer 4 is ready for serving.
[Preparation] Chef starts preparing meal for Customer 3
[Meal Ready] Meal for Customer 1 is ready for serving.
[Serving] Meal for Customer 1 is served.
[Preparation] Chef starts preparing meal for Customer 2
[Meal Ready] Meal for Customer 3 is ready for serving.
[Serving] Meal for Customer 3 is served.
[Meal Ready] Meal for Customer 2 is ready for serving.
[Serving] Meal for Customer 2 is served.
5 Replies
JavaBot
JavaBot3w ago
This post has been reserved for your question.
Hey @wajd! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
ayylmao123xdd
ayylmao123xdd3w ago
most likely happens because the chef thread grabs the order before its printed you could try placing the print before adding the order to the queue and check the results
JavaBot
JavaBot3w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
wajd
wajdOP3w ago
what's the suggestion? it should grab then print
JavaBot
JavaBot3w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server