Forum Navigation
Write into a file from a thread
Posted: 07/26/09 22:21:19Hi, 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 faultThis 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()); mutexout.lock(); doc.tree.element(null, "communication", cast(char[])client.Receive) .attribute(null, "address", client.GetAddr) .attribute(null, "protocol", protocol) .attribute(null, "port", Integer.toString(port)); logger.warn(docprint(doc)); output.write(docprint(doc)); Stdout("FINISHED").newline; mutexout.unlock(); 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:15Solved, 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