Pumpkin, Inc.

Pumpkin User Forums

When to clear EFlags when multiple processes waiting

If you can't make Salvo do what you want it to do, post it here.

When to clear EFlags when multiple processes waiting

Postby aek » Thu Jul 17, 2003 1:19 am

Hi Gerard.

How exactly are you "listening to this EFlag" ?

Are you saying that you have multiple tasks, each waiting the eFlag, and your problem is that i) data changes, eFlags is signaled, ii) the various waiting tasks wake up because of the signaling, iii) the various tasks run, and act on the eFlag with their particular mask, and then iv) it's not clear as to when to clear the eFlag so this cycle can be repeated.

To be honest, I may be out of my league in being able to provide an elegant means of answering your question (assuming I've understaood it correctly). However, I'll give it a try ...

The fundamental problem you have is that in order not to miss data (e.g. signaling events), you need to accumulate those events, e.g. like a counting semaphore. That way, even if you are in the middle of servicing the first signaling, a second and third one can come along and will still be there even when the act of successfully waiting the first one results in it being "cleared".

In order not to lose signaling events, somewhere, on a per-bit basis, you need queues or counting semaphores or whatever. In effect, two-dimensional eFlags.

I can't see a clear, elegant and robust solution to this right now. How about posting to comp.arch.embedded or a similarly well-read newsgroup and see what they suggest?

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: When to clear EFlags when multiple processes waiting

Postby aek » Thu Jul 17, 2003 1:28 am

Hi Gerard.

Here's an overview of an idea: use a message queue to hold all signaling events. You can make the message format anything you want ... then dedicate a single task to be the "interface" between the messages and the eFlag. Said task only passes the (next) message onto the eFlag after some sort of handshaking with all of the tasks that are waiting on the eFlag.

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: When to clear EFlags when multiple processes waiting

Postby gerardlt » Thu Jul 17, 2003 6:43 am

Hello,

I have an interesting problem (aren't they always?):

I have a database module in my project, which is responsible for handling all data that is shared across multiple modules.

When an item of data changes I signal an EFlag, setting some bit to indicate the data item changed.

Multiple modules can listen to this EFlag, and will change their mask according to what data they are interested in.

I may also want to add additional listening modules in the future.

My problem is this: When to clear the EFlag.

From my understanding of http://www.pumpkininc.com/ubb/Forum7/HTML/000107.html I must wait until each listening process has tested the EFlag before I can clear it. Unfortunately, waiting could mean that some data changes are missed.

Any suggestions on how to find a solid, extendable solution to this problem?

(I can clarify, if my description isn't clear.)

------------------
Gerard Thornley
Electron Software

Gerard Thornley
Electron Software
gerardlt
 
Posts: 14
Joined: Tue May 13, 2003 11:00 pm
Location: Lancaster, UK

Re: When to clear EFlags when multiple processes waiting

Postby gerardlt » Thu Jul 17, 2003 10:34 am

Hi Andrew,

Thanks for the suggestions. I had thought briefly about using the message queue, but I didn't like the level of overhead involved. I was hoping there might be a simpler solution.

I have decided to allocate a single EFlag for the database, plus an additional EFlag for each listening (waiting) process, plus a task to read the database EFlag, write to all of the other EFlags, then clear the database EFlag.
Each of the processes will then be responsible for clearing it's own EFlag when it has responded to the data change.

As I don't think the set of listening processes will be dynamically changing, so I can define a nice static array of (pointers to) EFlags (in ROM) to update, and keep the memory overhead fairly low ( 1T + (1 + n)E ).

A thought for future Salvo implementations:

Could EFlags store their wakeup condition when they are set, so that signalling code written as:
OSSetEFlag( ... );
OSClrEFlag( ... );
would still cause waiting processes to be woken up.

As this would be significantly different from current behaviour, it would have to be a new kind of EFlag, which could be confusing...

Another thought: Could a 'composite' event be programmed, which could listen to multiple events, and wake-up when any/all have occurred (a bit like an EFlag, but listening to other events)?

Many thanks,

------------------
Gerard Thornley
Electron Software

Gerard Thornley
Electron Software
gerardlt
 
Posts: 14
Joined: Tue May 13, 2003 11:00 pm
Location: Lancaster, UK

Re: When to clear EFlags when multiple processes waiting

Postby aek » Thu Jul 17, 2003 10:41 am

Hi Gerard.

Your solution is an elegant one ... but how do you ensure that the task that reads and clears the database flag doesn't overwrite the other eFlags when you're signaling the database flag in quick succession?

As for future implementations, my thoughts are to rewrite the eFlag underpinnings so that the set, clr, etc. functionality is controlled by external functions, with Salvo providing a default set with basic functionality. IOW, the eFlag services would be somewhat extensible to easily accomodate additional functionality and behavior ...

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: When to clear EFlags when multiple processes waiting

Postby aek » Fri Jul 18, 2003 4:37 am

Hi Gerard.

OK, now I understand the original description, and how your solution addresses it ... thanks!

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: When to clear EFlags when multiple processes waiting

Postby gerardlt » Fri Jul 18, 2003 5:44 am

Ok, I thought I hadn't been very clear with that description. :-)

Actually, since all the events are coming from one place, I don't even need the distributing task and the first event flag, reducing the requirement to just n event flags for n listening processes.

Regards,

------------------
Gerard Thornley
Electron Software

Gerard Thornley
Electron Software
gerardlt
 
Posts: 14
Joined: Tue May 13, 2003 11:00 pm
Location: Lancaster, UK

Re: When to clear EFlags when multiple processes waiting

Postby gerardlt » Fri Jul 18, 2003 11:18 am

Hi Andrew,

quote:

Your solution is an elegant one ... but how do you ensure that the task that reads and clears the database flag doesn't overwrite the other eFlags when you're signaling the database flag in quick succession?

I think I may have confused the issue here with my original explanation.

The listening processes won't be responding to the bit pattern, but rather to the individual bits, so it doesn't matter if multiple masks are applied by the set function.
In fact, it is advantageous, because then if a data item is changed twice before a listening process can respond, it will only respond once when it gets around to it. (And the great thing about cooperative multitasking is that I don't need to put a lock on the EFlag while I'm responding to it!)

The new EFlag ideas sound interesting. Not sure I understand them, but they do sound interesting! :-)

Regards,

Gerard Thornley
Electron Software
gerardlt
 
Posts: 14
Joined: Tue May 13, 2003 11:00 pm
Location: Lancaster, UK


Return to Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron