Is there a Kotlin equivalent of Java’s Collections.synchronizedList ? Or is this not needed in Kotlin

If I try to use the Java List a warning message comes up “This class shouldn’t be used in Kotlin…” Java lists (and other collections) are mapped types in Kotlin. So you can use Collections.synchronizedList, and it takes and returns a Kotlin List or MutableList. OTOH, synchronizedList is rarely what you actually want: it works … Read more

How to implement a unmanaged thread-safe collection when I get this error: is not supported when compiling with /clr

It is not supported because the std::mutex implementation uses GetCurrentThreadId(). That’s a winapi function that is not supposed to be use in managed code since it might be running on a custom CLR host that doesn’t use threads to implement threading. This is the good kind of problem to have, it shows that you are … Read more

Within a C# instance method, can ‘this’ ever be null?

this can never be null, unless the method was called using a call instruction in hand-written IL. However, if you use the same Queue instance on multiple threads simultaneously, the queue will become corrupted and lose data. For example, if two items are added simultaneously to a near-capacity queue, the first item might be added … Read more

What are alternative ways to suspend and resume a thread?

You’ll want to use an AutoResetEvent EventWaitHandle. Say you want to do something like this (NOTE: don’t do this!): private Thread myThread; private void WorkerThread() { myThread = Thread.CurrentThread; while (true) { myThread.Suspend(); //Do work. } } public void StartWorking() { myThread.Resume(); } Like others have said, this is a bad idea. Even though only … Read more

Is boost shared_ptr thread safe?

boost::shared_ptr<> offers a certain level of thread safety. The reference count is manipulated in a thread safe manner (unless you configure boost to disable threading support). So you can copy a shared_ptr around and the ref_count is maintained correctly. What you cannot do safely in multiple threads is modify the actual shared_ptr object instance itself … Read more

DecimalFormat.format(double) in different threads

Just use this thread-safe snippet for NumberFormat: static ThreadLocal<NumberFormat> numberFormat = new ThreadLocal<NumberFormat>() { @Override public NumberFormat initialValue() { return new DecimalFormat(“00000”); } }; Or in Java 8, as Jesper said in comment: private static ThreadLocal<NumberFormat> numberFormatter = ThreadLocal.withInitial(() -> new DecimalFormat(“00000”));

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)