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

Write into a file from a thread

Moderators: larsivi kris

Posted: 07/26/09 22:21:19

Hi, i'm trying to write into a file from a thread, but i get

5052 Warn  bluebat.client.communication -
<communication address="00:1D:6E:9D:3C:CD" protocol="rfcomm" port="1">hello!</communication>
Segmentation fault

This is the code (only the useful one):

File output;
Mutex mutexout;
Document!(char) doc;
DocPrinter!(char) docprint;

static this(){
	output = new File("data.xml", File.WriteCreate);
	mutexout = new Mutex();
	doc = new Document!(char);
	docprint = new DocPrinter!(char);

int process_client(Communication client, char[] protocol, int port){
	auto logger = Log.lookup("bluebat.client.communication");
	logger.level = logger.Info;
	logger.add(new AppendFile("log.txt"));
	logger.add(new AppendConsole());
	doc.tree.element(null, "communication", cast(char[])client.Receive)
    .attribute(null, "address", client.GetAddr)
    .attribute(null, "protocol", protocol)
    .attribute(null, "port", Integer.toString(port));
	return 0;

When "output.write(docprint(doc));" is executed it dsegfaults. The "process_client" function is called from a thread of the ThreadPool?.

Does anyone know how to solve this issue? thanks

Author Message

Posted: 07/27/09 08:53:15

Solved, it was that i called output.close() somewhere in my code and then i tried to write in it.

This happens when you code at 2 AM :)

See you