comp.lang.ada
 help / color / mirror / Atom feed
* Resolving a deadlock
@ 2004-08-25  0:28 Daniel Wild
  2004-08-25  0:45 ` Jeffrey Carter
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Wild @ 2004-08-25  0:28 UTC (permalink / raw)


Hi,

I got a deadlock problem that I'm trying to resolve but I can't find a
way to get it to work. The situation is:

Task A is calling an entry in Task B to tell it to shut down, but
Task B is calling an entry in Task A to pass it some data.

The obvious solution is to add a select ... or delay ... end select
construct around the call from Task B to Task A so that it will time
out and be able to accept the call from Task A to shut down.

But, Task B looks something like this (this might not compile, but
it's the same idea):

generic
   with procedure Task_Entry;
package B_Package is
   task type B_Task_Type is
      entry Start;
      entry Stop;
   end B_Task_Type;

   task body B_Task_Type is
   begin
      select
         accept Start;
      or 
         terminate;
      end select;

      loop
         select 
            accept Stop;
            exit;
         or
            delay 0.1;
            -- Do some processing
            -- ...
            -- Call task entry
            Task_Entry;
         end select;
      end loop;
   end B_Task_Type;
end B_Package;

Adding a select ... or delay ... end select around the call to
Task_Entry in the   Task B main loop causes a compiler error because
it needs a task entry. The compiler thinks that it is just a procedure
because that's the way it is passed in when the package is
instantiated.

So, to fix that you would pass in a procedure as Task_Entry, and in
that procedure do the timed entry call, right? Well, that works. The
problem with that is that this is only one implementation of this
package, and the other one relies on Task_Entry (the generic
parameter) being a task entry. Using a procedure for this won't work
on the other implementation.

Has anyone got any ideas on another way to make this work? I've had a
look for pragmas to tell the compiler that it really is a Task_Entry,
but things like pragma Convention don't ley you specify 'Entry' as the
calling convention.

I'm using ObjectAda 7.2.2 for this (the other implementation uses Apex
2.0.8C).

Daniel.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Resolving a deadlock
  2004-08-25  0:28 Resolving a deadlock Daniel Wild
@ 2004-08-25  0:45 ` Jeffrey Carter
  0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey Carter @ 2004-08-25  0:45 UTC (permalink / raw)


Daniel Wild wrote:
> 
> Task A is calling an entry in Task B to tell it to shut down, but
> Task B is calling an entry in Task A to pass it some data.

The simple solution is to put a protected object between the 2 tasks. 
That way B can get either the shut down indication or the data from a 
single call.

-- 
Jeff Carter
"I wave my private parts at your aunties."
Monty Python & the Holy Grail
13




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-08-25  0:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-25  0:28 Resolving a deadlock Daniel Wild
2004-08-25  0:45 ` Jeffrey Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox