Tuesday, 15 April 2014

c# - Thread safety of StringBuilder class -



c# - Thread safety of StringBuilder class -

class test { public string getdata() { stringbuilder sb = new stringbuilder(); sb.append("aassffss"); sb.append("bbhhhhh"); homecoming sb.tostring(); } } // calling multithreads,as below, // each thread create new // instance , phone call method. test t = new test(); t.getdata();

as per msdn. instance fellow member of stringbuilder class not thread safe. believe not thread safe. correct?

this code thread safe because no instances shared between threads.

you encounter problem had single instance shared between multiple threads. then, if had multiple instance method calls different threads, on same instance, code unsafe.

c# multithreading thread-safety stringbuilder

No comments:

Post a Comment