process - Multithreading logic -


multihreading way on me. not ask specific code, instead i'd me on logical structure of problem.

we have restaurant 2 waiters, taking orders customers instantly meaning free (not serving) take order customer in front of line, , process (serve them) these orders randomly (in time range, not instantly). customers in line, , whichever waiter not serving @ moment, take orders.

i have function called getinline() generator of customers, uses sleep() function before each customer being added line.

i have function called takeorders() (supposedly) takes orders customers. problem is, in function have function call made servecostumer() instantly serves customer. if make function sleep() sleeps , serves customer want of course multitasking/threading, should like:

  • customer 1 came
  • waiter 1 took order
  • customer 2 came
  • waiter 2 took order
  • 3 came
  • waiter 1 served customer 1
  • customer 4 came
  • waiter 2 served customer 2

mainly ask is, can me visualize in code level? mean

takeorders...
lock here
unlock here

call , that
etc..

something that.

the essence of problem seems need 2 seperate actions, occuring @ different times.

  1. 2 waiters serving customers(which takes time)
  2. customers being added queue @ random times.

i argue mutex overkill here. if want include locking mechanism, add switch called hasbeenserved customers, which, before serving customer, checked , flipped waiter if false. if true, go next customer.

in terms of threads, easiest solution have following threads:

  1. waiter 1
  2. waiter 2
  3. customer line

and kick them off @ once. i'm no multithreading expert, how approach it.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -