www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Strange bug in std.concurrency.spawn

reply Jose Armando Garcia <jsancio gmail.com> writes:
dmd can compile and run to follow the code:

unittest
{
   spawn(&fun);
}

void fun(int i) { writeln(i); }

Which if you are lucky segfaults and if you are unlucky prints
garbage! The problem is that spawn doesn't checks that the signature
of fun matches the number and type of variadic arguments. Is this a
bug in spawn(), a bug in dmd or a limitation of the language?

* If it is a bug in spawn, how can it be augmented to check this case?
* If this is a bug in dmd, I'll file a report.
* If this is a limitation of the language is this well known and it is
worked on? As it stands it doesn't seem possible to write safe
multi-threaded code.
Apr 04 2011
next sibling parent Nick Treleaven <nospam example.net> writes:
On Tue, 05 Apr 2011 01:19:08 -0300, Jose Armando Garcia wrote:

 dmd can compile and run to follow the code:
 
 unittest
 {
    spawn(&fun);
 }
 
 void fun(int i) { writeln(i); }
 
 Which if you are lucky segfaults and if you are unlucky prints garbage!
 The problem is that spawn doesn't checks that the signature of fun
 matches the number and type of variadic arguments. Is this a bug in
 spawn(), a bug in dmd or a limitation of the language?
 
 * If it is a bug in spawn, how can it be augmented to check this case? *
 If this is a bug in dmd, I'll file a report. * If this is a limitation
 of the language is this well known and it is worked on? As it stands it
 doesn't seem possible to write safe multi-threaded code.

It's not a language limitation. The signature is: Tid spawn(T...)( void function(T) fn, T args ); So the compiler should ensure that fn(args) is typesafe. Please search bugzilla for this bug and report it if not found.
Apr 07 2011
prev sibling parent David Nadlinger <see klickverbot.at> writes:
This is a DMD bug, and fixed in the pending pull request 91: 
https://github.com/D-Programming-Language/dmd/pull/91

David


On 4/5/11 6:19 AM, Jose Armando Garcia wrote:
 dmd can compile and run to follow the code:

 unittest
 {
     spawn(&fun);
 }

 void fun(int i) { writeln(i); }

 Which if you are lucky segfaults and if you are unlucky prints
 garbage! The problem is that spawn doesn't checks that the signature
 of fun matches the number and type of variadic arguments. Is this a
 bug in spawn(), a bug in dmd or a limitation of the language?

 * If it is a bug in spawn, how can it be augmented to check this case?
 * If this is a bug in dmd, I'll file a report.
 * If this is a limitation of the language is this well known and it is
 worked on? As it stands it doesn't seem possible to write safe
 multi-threaded code.

Jun 07 2011