www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - "Aliases to mutable thread-local data not allowed" when using spawn()

reply "D_Beginner" <mailsnachhier-privat yahoo.de> writes:
Hi there,

I'm quite new do D, but from what I've seen so far, I really like 
it.
I tried to implement a very basic chatclient that I've written in 
  Go before, and put the logics to send messages in a send() 
function, looking like this:

void send(TcpSocket sock) {
	while(true) {
		write("Message: ");
		auto msg = strip(readln());
		sock.send(msg);
	}
}

Of course I need this function to run concurrently for I have to 
check for answers from the server at the same time. But when I 
try to launch it in an own thread:

spawn(&send, sock);

I get this strange error:

"Error: static assert "Aliases to mutable thread-local data not 
allowed""

Why is that? How can I make my function(s) run concurrently if 
not in that way?

thanks in advance, D_Beginner.
Dec 02 2012
next sibling parent "D_Beginner" <mailsnachhier-privat yahoo.de> writes:
On Sunday, 2 December 2012 at 15:47:36 UTC, D_Beginner wrote:
 Hi there,

 I'm quite new do D, but from what I've seen so far, I really 
 like it.
 I tried to implement a very basic chatclient that I've written 
 in
  Go before, and put the logics to send messages in a send() 
 function, looking like this:

 void send(TcpSocket sock) {
 	while(true) {
 		write("Message: ");
 		auto msg = strip(readln());
 		sock.send(msg);
 	}
 }

 Of course I need this function to run concurrently for I have 
 to check for answers from the server at the same time. But when 
 I try to launch it in an own thread:

 spawn(&send, sock);

 I get this strange error:

 "Error: static assert "Aliases to mutable thread-local data not 
 allowed""

 Why is that? How can I make my function(s) run concurrently if 
 not in that way?

 thanks in advance, D_Beginner.
Alright, I changed from std.concurrency to std.parallelism and it works fine.
Dec 02 2012
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Sunday, December 02, 2012 16:47:35 D_Beginner wrote:
 Hi there,
 
 I'm quite new do D, but from what I've seen so far, I really like
 it.
 I tried to implement a very basic chatclient that I've written in
   Go before, and put the logics to send messages in a send()
 function, looking like this:
 
 void send(TcpSocket sock) {
 	while(true) {
 		write("Message: ");
 		auto msg = strip(readln());
 		sock.send(msg);
 	}
 }
 
 Of course I need this function to run concurrently for I have to
 check for answers from the server at the same time. But when I
 try to launch it in an own thread:
 
 spawn(&send, sock);
 
 I get this strange error:
 
 "Error: static assert "Aliases to mutable thread-local data not
 allowed""
 
 Why is that? How can I make my function(s) run concurrently if
 not in that way?
 
 thanks in advance, D_Beginner.
Read this: http://www.informit.com/articles/article.aspx?p=1609144 - Jonathan M Davis
Dec 02 2012