Sequencially executing the WorkItem

Hi,

is there a way we can execute WorkItem in sequence, In sequence i mean
whichever workitem enqueued first should be executed first.

As per my knowledge after we enqueue the workitem system thread will remove
the workitem and start executing but if suppose in workitem i am holding
any lock for synchronization then it might be the situation where the
workitem which is en-queued later might get the lock than the workitem
which was en-queued before that.

The only way i see to sequentially do it create our own queue and push the
data to it and create a thread that will pick those events and executes it.

Please suggest!

Regars,
Rabish

If you need order, create a queue of work that you maintain. You can service the queue with a work item or your own thread

d

Bent from my phone


From: Ravish Yadavmailto:xxxxx
Sent: ?5/?11/?2015 5:45 PM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: [ntdev] Sequencially executing the WorkItem

Hi,

is there a way we can execute WorkItem in sequence, In sequence i mean whichever workitem enqueued first should be executed first.

As per my knowledge after we enqueue the workitem system thread will remove the workitem and start executing but if suppose in workitem i am holding any lock for synchronization then it might be the situation where the workitem which is en-queued later might get the lock than the workitem which was en-queued before that.

The only way i see to sequentially do it create our own queue and push the data to it and create a thread that will pick those events and executes it.

Please suggest!

Regars,
Rabish
— NTDEV is sponsored by OSR Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev OSR is HIRING!! See http://www.osr.com/careers For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

If order matters to you then yes, make your own queue with the data packets you want to process, then queue one work item to process the queue.

-p

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Ravish Yadav
Sent: Monday, May 11, 2015 5:45 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Sequencially executing the WorkItem

Hi,

is there a way we can execute WorkItem in sequence, In sequence i mean whichever workitem enqueued first should be executed first.

As per my knowledge after we enqueue the workitem system thread will remove the workitem and start executing but if suppose in workitem i am holding any lock for synchronization then it might be the situation where the workitem which is en-queued later might get the lock than the workitem which was en-queued before that.

The only way i see to sequentially do it create our own queue and push the data to it and create a thread that will pick those events and executes it.

Please suggest!

Regars,
Rabish
— NTDEV is sponsored by OSR Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev OSR is HIRING!! See http://www.osr.com/careers For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Enqueue the second work item from within the first work item.

“Ravish Yadav” wrote in message news:xxxxx@ntdev…
Hi,

is there a way we can execute WorkItem in sequence, In sequence i mean whichever workitem enqueued first should be executed first.

As per my knowledge after we enqueue the workitem system thread will remove the workitem and start executing but if suppose in workitem i am holding any lock for synchronization then it might be the situation where the workitem which is en-queued later might get the lock than the workitem which was en-queued before that.

The only way i see to sequentially do it create our own queue and push the data to it and create a thread that will pick those events and executes it.

Please suggest!

Regars,
Rabish

Hi Maxim,

Could not get you how it will help can you elaborate more on this.

Regards,
Rabish

On Wed, May 13, 2015 at 5:14 PM, Maxim S. Shatskih
wrote:

> Enqueue the second work item from within the first work item.
>
>
> “Ravish Yadav” wrote in message
> news:xxxxx@ntdev…
> Hi,
>
> is there a way we can execute WorkItem in sequence, In sequence i mean
> whichever workitem enqueued first should be executed first.
>
> As per my knowledge after we enqueue the workitem system thread will
> remove the workitem and start executing but if suppose in workitem i am
> holding any lock for synchronization then it might be the situation where
> the workitem which is en-queued later might get the lock than the workitem
> which was en-queued before that.
>
> The only way i see to sequentially do it create our own queue and push the
> data to it and create a thread that will pick those events and executes it.
>
> Please suggest!
>
> Regars,
> Rabish
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

> >Enqueue the second work item from within the first work item.

Could not get you how it will help can you elaborate more on this.

You cannot be THAT obtuse, can you…

If enqueueing of the second workitem is done on the last line that the first workitem’s routine executes the second workitem will run later than the first one, at least as far as all the resources that workitem routine accesses are concerned.Is it too difficult to understand???

Anton Bassov

Or even easier (suddenly came to mind) - just use 1 workitem, and call the 2nd one as a direct function call from the 1st one.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntdev…
> > >Enqueue the second work item from within the first work item.
>
>>Could not get you how it will help can you elaborate more on this.
>
> You cannot be THAT obtuse, can you…
>
> If enqueueing of the second workitem is done on the last line that the first workitem’s routine executes the second workitem will run later than the first one, at least as far as all the resources that workitem routine accesses are concerned.Is it too difficult to understand???
>
>
> Anton Bassov
>

While pounding innocents is fun, it is also rude.

Mark Roddy

On Wed, May 13, 2015 at 9:23 AM, wrote:

> > >Enqueue the second work item from within the first work item.
>
> >Could not get you how it will help can you elaborate more on this.
>
> You cannot be THAT obtuse, can you…
>
> If enqueueing of the second workitem is done on the last line that the
> first workitem’s routine executes the second workitem will run later than
> the first one, at least as far as all the resources that workitem routine
> accesses are concerned.Is it too difficult to understand???
>
>
> Anton Bassov
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

I suggest creating a system thread to process your own work queue.

On Wed, May 13, 2015 at 10:05 AM, Mark Roddy wrote:

> While pounding innocents is fun, it is also rude.
>
> Mark Roddy
>
> On Wed, May 13, 2015 at 9:23 AM, wrote:
>
>> > >Enqueue the second work item from within the first work item.
>>
>> >Could not get you how it will help can you elaborate more on this.
>>
>> You cannot be THAT obtuse, can you…
>>
>> If enqueueing of the second workitem is done on the last line that the
>> first workitem’s routine executes the second workitem will run later than
>> the first one, at least as far as all the resources that workitem routine
>> accesses are concerned.Is it too difficult to understand???
>>
>>
>> Anton Bassov
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>>
>> OSR is HIRING!! See http://www.osr.com/careers
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>
> — NTDEV is sponsored by OSR Visit the list at:
> http://www.osronline.com/showlists.cfm?list=ntdev OSR is HIRING!! See
> http://www.osr.com/careers For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Jamey Kirby
Disrupting the establishment since 1964

This is a personal email account and as such, emails are not subject to
archiving. Nothing else really matters.

Hi Anton,

You are right I am not that obtuse my question here is for situation where
hardware is generating interrupts and I am enquing the work item in this
situation without managing my own queue is it possible to execute work item
in sequence no right

For that if I manage my own queue of interrupt data to process than I can
obiously have control over and can use this recursive scheme.

Regards,
Rabish
On Wednesday, May 13, 2015, wrote:

> > >Enqueue the second work item from within the first work item.
>
> >Could not get you how it will help can you elaborate more on this.
>
> You cannot be THAT obtuse, can you…
>
> If enqueueing of the second workitem is done on the last line that the
> first workitem’s routine executes the second workitem will run later than
> the first one, at least as far as all the resources that workitem routine
> accesses are concerned.Is it too difficult to understand???
>
>
> Anton Bassov
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Mr Anton,

While replying you should think that anyone will not ask question regarding
recursion or calling other function on last line.
With due respect
You are very senior member of this group but I have reading all your
replies I think this is in your behavior so plz do not simply reply my
questions if you can not use nice language.

On Wednesday, May 13, 2015, Ravish Yadav wrote:

> Hi Anton,
>
> You are right I am not that obtuse my question here is for situation where
> hardware is generating interrupts and I am enquing the work item in this
> situation without managing my own queue is it possible to execute work item
> in sequence no right
>
> For that if I manage my own queue of interrupt data to process than I can
> obiously have control over and can use this recursive scheme.
>
>
> Regards,
> Rabish
> On Wednesday, May 13, 2015, > <javascript:_e>> wrote:
>
>> > >Enqueue the second work item from within the first work item.
>>
>> >Could not get you how it will help can you elaborate more on this.
>>
>> You cannot be THAT obtuse, can you…
>>
>> If enqueueing of the second workitem is done on the last line that the
>> first workitem’s routine executes the second workitem will run later than
>> the first one, at least as far as all the resources that workitem routine
>> accesses are concerned.Is it too difficult to understand???
>>
>>
>> Anton Bassov
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>>
>> OSR is HIRING!! See http://www.osr.com/careers
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
></javascript:_e>

> You are very senior member of this group but I have reading all your

replies I think this is in your behavior so plz do not simply reply my
questions if you can not use nice language.

Duh!!! Looks like I made yet another “enemy”. I DO see the point- indeed, I may be quite rude and impatient with people, especially if they don’t seem particularly bright to me. My only excuse is that my “rudeness” in this case was not necessarily uncalled for - after all, a guy who asked how to convert LARGE_INTEGER to DWORD was treated more or less the same way by absolutely everyone who replied to him.

In any case, let’s get back to the technical part. Assuming that you don’t want to create a dedicated thread (which is, probably, the easiest option here anyway) your problem can be solved just trivially. In DPC routine you do it the following way (in pseudocode):

spinlock();

add_instance_data_to_your_queue();

count ++;

if(count==1)enqueue_workitem();

spin_unlock();

In workitem routine(again,in pseudocode):

void workitem_routine()
{

spinlock();

get_and_remove_instance_data_from_your_queue();

spin_unlock();

do_actual_workitem_processing();

spinlock();

count --;

if(count)enqueue_workitem();

spin_unlock();

}

If you do it this way all your processing will be self-serialized without any dedicated threads anywhere in sight. What is so terribly complex here???

Anton Bassov

> Or even easier (suddenly came to mind) - just use 1 workitem, and call the 2nd

one as a direct function call from the 1st one.

Well, this approach is, probably, not easier, but definitely more efficient compared to enqueueing a workitem every time you want to run a workitem routine. Therefore, we can think of it just as of an optimization. If we take this approach, our pseudocode in workitem routine can be written the following way (the one in DPC does not need any changes):

void workitem_routine()
{

spinlock();

while(1)

{

get_and_remove_instance_data_from_your_queue();

spin_unlock();

do_actual_workitem_processing();

spinlock();

count --;

if(!count){spin_unlock();break;}

}

}

Anton Bassov

People post here to know the expert advise because they might not have much
experience in particular environment that does not mean that anyone can use
the rude language.

Anyway thanks !

On Thursday, May 14, 2015, wrote:

> > You are very senior member of this group but I have reading all your
> > replies I think this is in your behavior so plz do not simply reply my
> > questions if you can not use nice language.
>
> Duh!!! Looks like I made yet another “enemy”. I DO see the point- indeed,
> I may be quite rude and impatient with people, especially if they don’t
> seem particularly bright to me. My only excuse is that my “rudeness” in
> this case was not necessarily uncalled for - after all, a guy who asked how
> to convert LARGE_INTEGER to DWORD was treated more or less the same way by
> absolutely everyone who replied to him.
>
>
> In any case, let’s get back to the technical part. Assuming that you don’t
> want to create a dedicated thread (which is, probably, the easiest option
> here anyway) your problem can be solved just trivially. In DPC routine you
> do it the following way (in pseudocode):
>
> spinlock();
>
> add_instance_data_to_your_queue();
>
> count ++;
>
> if(count==1)enqueue_workitem();
>
> spin_unlock();
>
>
> In workitem routine(again,in pseudocode):
>
> void workitem_routine()
> {
>
> spinlock();
>
> get_and_remove_instance_data_from_your_queue();
>
>
> spin_unlock();
>
>
> do_actual_workitem_processing();
>
>
> spinlock();
>
>
> count --;
>
> if(count)enqueue_workitem();
>
> spin_unlock();
>
> }
>
> If you do it this way all your processing will be self-serialized without
> any dedicated threads anywhere in sight. What is so terribly complex
> here???
>
>
>
> Anton Bassov
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

> People post here to know the expert advise because they might not have much

experience in particular environment that does not mean that anyone can use
the rude language.

Sure, but, in this particular case, the problem seems to lie somewhere deeper than just in the lack of
“experience in particular environment”, don’t you think? Instead, it seems to be rooted in the lack of something much more fundamental, especially taking your reaction to Max’s suggestion which, indeed, provoked me to speak to you the way I did…



Call me an arsehole (or, probably, even a C-word - I don’t care anyway) if you wish, but, in my opinion, quite a few of “NTDEV regulars” may be unnecessarily helpful and friendly with certain posters. To be honest, I am just shocked to see the entire NTDEV teaching the basics of C language to yet another “kernel would-be guru”, or patiently explaining to them why they cannot open a handle for the exclusive access before all open handles on the target device are closed, or, in the extreme cases, even teaching them how to perform the tasks as “complex” as renaming a file in Windows Explorer (no, I am not making it up - just search the archives)…

Anton Bassov

anton bassov wrote:

even teaching them how to perform the tasks as “complex”
as renaming a file in Windows Explorer (no, I am not making it up -
just search the archives)…

To be fair, I think Max drew the line at condoning kernel developers who didn’t know what file extensions were…when others (I won’t say who, but I think their name rhymes with Jim Floberts) said something to the effect of “well, we were all inexperienced once.”

I think “convert LARGE_INTEGER to DWORD” thread was an exception to this rule - even “Jim” had to admit that the OP’s treatment was not totally undeserved…

Anton Bassov

Yes, and your interrupt queue can be just a bitmask of “this kind of interrupt fired” bits.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com
“Ravish Yadav” wrote in message news:xxxxx@ntdev…
Hi Anton,

You are right I am not that obtuse my question here is for situation where hardware is generating interrupts and I am enquing the work item in this situation without managing my own queue is it possible to execute work item in sequence no right

For that if I manage my own queue of interrupt data to process than I can obiously have control over and can use this recursive scheme.

Regards,
Rabish
On Wednesday, May 13, 2015, wrote:

> >Enqueue the second work item from within the first work item.

>Could not get you how it will help can you elaborate more on this.

You cannot be THAT obtuse, can you…

If enqueueing of the second workitem is done on the last line that the first workitem’s routine executes the second workitem will run later than the first one, at least as far as all the resources that workitem routine accesses are concerned.Is it too difficult to understand???

Anton Bassov


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Still struggling to get your Thorazine levels properly adjusted I see, Mr. Bassov… Ah, that CAN be tough. May I suggest you increase your dosage just a bit.

As one of my co-workers is fond of saying: “Try being NICE. You might LIKE it.”

Peter
OSR
@OSRDrivers

> Still struggling to get your Thorazine levels properly adjusted I see, Mr. Bassov…

Intrigued by the above statement, I decided to Google a bit. This is what I found:



Chlorpromazine (CPZ) ? marketed, as chlorpromazine hydrochloride, in the United States as Thorazine and elsewhere as Largactil and Megaphen ? is a dopamine antagonist of the typical anti-psychotic class of medications possessing additional anti-adrenergic, anti-serotonergic, anti-cholinergic and anti-histaminergic properties used to treat schizophrenia.

How come that you are so well-informed about anti-psychotic medications, Peter? To be honest, I would normally expect THIS level of knowledge only either from a doctor or from a patient, and I cannot immediately recall you ever telling us about your degree in psychiatry…

Ah, that CAN be tough. May I suggest you increase your dosage just a bit.

Are you judging it from a first-hand experience or is it just a professional advice? Again,
I cannot immediately recall you ever telling us about being a psychiatry practitioner, but it does not mean anything anyway - after all, I might well have been just too busy attacking
MSFT/Windows/some"kernel-would-be-guru"/etc to notice this info…

As one of my co-workers is fond of saying: “Try being NICE. You might LIKE it.”

Unless we assume that you are affected by synesthesia, I just wonder how someone can say something in capitals. Does he/she/it actually say it or just sticks the posters on the walls all over the place?

In any case, I tried hard enough to follow the above mentioned advice on this thread - so hard that even provided the OP with a schematic code that he can use. The only thing that I am still unable to understand (I must be just too thick) is why the OP needs any external assistance with something as basic and obvious as a solution to his original problem.I think that typing in his original question took him more time than he would have otherwise spent typing the code had he “turned his brains on”, instead of crying “Mommy…Daddy…please help…”

Anton Bassov