Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #2046 (new defect)

Opened 13 years ago

tango.core.Signal not thread-safe

Reported by: rawler Assigned to: community
Priority: major Milestone: 1.0
Component: Tango Version: 0.99.9 Kai
Keywords: signal, concurrency, threading Cc: kris

Description

tango.core.Signal as of current implementation suffers from a few threading-issues.

The root problem is that the various "synchronized" statements in the code are really only synchronizing access to each individual block, but not between each other.

Some consequences are;

  • Majorly, since each section is globally locked, if code in delegates of opCall with one certain signature (say, Signal!(int)), issues an opCall with another signature Signal!(), and other unrelated code in separate thread opCall:s on other unrelated signals of the same signatures revursively in reverse order, the two threads will deadlock.
  • Even though Signal looks thread-safe, it's really not, not even for unicore systems, since there is a small chance the m_blk-test of attach() may be done just before m_blk is set in opCall, and the two routines may then proceed in parallel, with unpredicatable results.
  • The code, without beeing thread-safe, requires locking on each iteration, degrading performance.

In general, three degrees of thread-safe implementations are imaginable;

  1. Not-at-all thread-safe. Just assume single-threaded operation. Fastest and simplest.
  2. Synchronized on a instance-local mutex. Slower, if delegates are called while holding the lock, it is still possible to deadlock. Slowest option, but still farily simple.
  3. Completely concurrent, with correct memory barries. Fairly fast, but complex implementation.

I'm attaching a proposed hybrid of 1 and 3. It is lock-less, and thread-safe for uni-processor systems, but I lack the concurrency-programming skills for making it fully concurrent and safe.

Attachments

Signal.d (4.8 kB) - added by rawler on 04/16/11 19:04:31.
Proposed implementation

Change History

04/16/11 19:04:31 changed by rawler

  • attachment Signal.d added.

Proposed implementation