Hi Marcel,

2011/12/16 Marcel Offermans <[email protected]>:
> With the risk of sounding like a school teacher (which I'm trying to
> avoid)...

Haha.. I don't mind some education so don't hold back on my account :)

> Up to here we're fine. We are invoking the dependency manager, but only
> declaring a component without actually handing it to the manager is fine.
>
>         m_dependencyManager.add(component);

Ok, clear and just found this is actually documented in the spec under 4.7.3

{quote}
4.7.3 Synchronization Pitfalls
Generally, a bundle that calls a listener should not hold any Java monitors.
This means that neither the Framework nor the originator of a synchronous
event should be in a monitor when a callback is initiated.
The purpose of a Java monitor is to protect the update of data structures.
This should be a small region of code that does not call any code the effect of
which cannot be overseen. Calling the OSGi Framework from synchronized
code can cause unexpected side effects. One of these side effects might be
deadlock. A deadlock is the situation where two threads are blocked because
they are waiting for each other.
Time-outs can be used to break deadlocks, but Java monitors do not have
time-outs. Therefore, the code will hang forever until the system is reset
(Java has deprecated all methods that can stop a thread). This type of deadlock
is prevented by not calling the Framework (or other code that might
cause callbacks) in a synchronized block.
If locks are necessary when calling other code, use the Java monitor to create
semaphores that can time-out and thus provide an opportunity to escape a
deadlocked situation.
{quote}

Now this is all fine, but as you are in teacher mode... *scary voice
of Igor* why!?

It always feels awkward to have a dynamic services architecture and
then when thinking about interface semantics having to be aware and
concerned with how the framework and consumers handle threads when it
comes to side effects. I can only guess about OSGi design choices and
am afraid something like "resource constraint devices' is in the
answers, but obviously something like sync life-cycle events is a
recipe for deadlocks. So, without trying to redesign OSGi, for
example... Why don't we have an async add(Component)?

grz
Bram

_______________________________________________
Amdatu-developers mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-developers

Reply via email to