Re: output.c error in multithreaded program

From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 12/29/04


Date: Wed, 29 Dec 2004 14:01:17 -0500

On Mon, 27 Dec 2004 12:28:13 -0000, "Joe" <not@home.com> wrote:

>
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>news:81dvs0hgpp195fhu2usp9j6pj37i772srt@4ax.com...
>> CWinThread::Create is essentially AfxBeginThread. Rarely is it necessary
>to create an
>> instance of CWinThread and start it separately.
>>
>> pThread = (CThreadType1 *)AfxBeginThread(CThreadType1::ThreadFunc,
>ThreadParams);
>
>> >Firstly.
>> >#####
>> >
>> >I want to set up priorites for the
>> >threads to access the internet - but I could find any examples so I set
>up
>> >this structure using semaphores. I include the function desc which should
>> >explain my rationale
>> >
>>
>>dwRet=GetHttpFileHarness(LOW_PRIORITY,pThrPars->m_strServerName,pThrPars->m
>_
>> >strObject, pThrPars,FALSE);
>> ****
>> I don't know what you mean by "priorities". Do you mean that requests will
>not be in FIFO
>> order? That's easy: just modify your queue insertion routine to put the
>request in the
>> queue in priority order.
>
>Well I was trying to be clever. Dont forget there are several processes with
>several groups.
>So I dont have a single queue.
>The application sees type A header data as more important than C. I didn't
>want a process thread drilling a header page having to wait for 20 type C
>threads to finish downloading their pages in another group or even another
>process entirely.
>The other motivation was that I dont want to hit the server hard, I restrict
>the global semaphores to 6 in total - so I can only be making 6 requests at
>a time. A new type 'A' request may get stuck behind 100 type C requests if I
>can't have some sort of prioritisation.
*****
Then there's something wrong with your structure. Type A requests would go in a type A
queue, type C requests in a type C queue. Alternatively, a type A request migrates past
all type C requests in a queue until it hits a type A request. Thus you implement
priorities easily. But using thread priorities to try to implicitly implement a notion of
application importance is almost always a bad idea, because you are working under the
illusion that these priorities actually mean something. Think of them as "suggestions"
which the system may or may not honor. Because the Balance Set Manager will boost a
starved thread to priority 15 at random times, you don't have any way to enforce the
notion that all A threads will always preempt all C threads. Messing with priorities is
risky business. Every once in a while you need to, but it should not be considered a way
of doing business. It offers no real guarantees.

The problem is that there are several problems you are trying to solve with fairly complex
mechanisms. Instead, you need to reparition your program into simpler tasks, and address
the tasks. The mechanisms that fall out will be fairly straightforward.

I've built some really complex multithreaded programs in my career, and I've learned that
simpler structures are better. Overall, I just try to keep everything as simple as
possible, working from the goal back to the mechanisms. Otherwise, the complexity of the
mechanisms blinds you about the goal.

For example, one thing you've said is that there can be several processes. A question is
"why?" Why not a single process? But if the processes are independent, then the number of
them doesn't really matter; if you solve the problem once; it is then solved for all
processes.
*****
>
>I simply couldn't/can't work out how to do this in an elegant way - hence my
>brute-force hard-coding approach to always leave 2 slots clear for type A
>HTTP requests.
>
>
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm



Relevant Pages

  • [rfc][patch 2.6.18-rc7] block: explicit plugging
    ... This is a patch to perform block device plugging explicitly in the submitting ... the device idle when it is known more requests will be submitted. ... Explicit plugging keeps a process-private queue of requests being held. ... struct rb_root cic_root; ...
    (Linux-Kernel)
  • Re: output.c error in multithreaded program
    ... >> queue, type C requests in a type C queue. ... But since multiple processes actually involve more overhead than ... limits and didn't pursue the upper bound issue. ...
    (microsoft.public.vc.mfc)
  • Re: [PATCH] O12.2int for interactivity
    ... > queue, and the other is the expired queue. ... 2.6.x has implemented is incremental timeslice assignment for epoch ... re-inserted near the head of the queue as their priorities are high ...
    (Linux-Kernel)
  • Re: Problem of creating control device in a mouse filter driver us
    ... Number of driver owned requests: ... This is WDF internal queue for create requests. ... The control device and filter device seem both have their own IOqueues. ...
    (microsoft.public.development.device.drivers)
  • Re: Synchronization methodology
    ... instances of a single class (in simpler terms, ... the Queue module). ... requests from a queue: ... Then in your connected user thread you could say: ...
    (comp.lang.python)

Loading