lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


on 2/27/08 5:54 AM, Renato Maia at maia@inf.puc-rio.br wrote:

> I'm probably missing something, but what's wrong with the following
> code?
> 
> while true do
> 
>      if not test_condition_1() then
>          wait_for_semaphore_1()
> 
>      elseif not test_condition_2() then
>          wait_for_semaphore_2()
> 
>      else
>          -- conditions 1 and 2 now hold
>      end
> 
> end

Nothing. But sometimes one wants more logic which gets in the way of the if.
For example:

    while true do repeat

        if processing_suspended() then
            wait_until_processing_not_suspended()
            break -- continue
        end

        local item = queue:peekFront()

        if not item then
            wait_queue_non_empty()
            break -- continue
        end

        if item:onlyOnTuesdays() then
            wait_until_Tuesday()
            break -- continue
        end

        -- Now it's okay to go process the item

        queue:popFront()

        -- Process

Mark