Debugger stops at JsonConvert.DeserializeObject


Debugger stops at JsonConvert.DeserializeObject



I have a class 'FixedSizeStack' as shown below.


public class FixedSizeStack
{
public int top;
public string stack;
public int maxSize;

public FixedSizeStack(int size)
{
maxSize = size;
stack = new string[size];
}

}



In my program, the debugger stops at the below line and it doesn't proceed further


EntityStack = JsonConvert.DeserializeObject<FixedSizeStack>(cacheManager.Get("XYZ"))



soon the CPU percentage reaches 100%. What could be the root cause?





Possibly an infinite loop. What is the expected value of cacheManager.Get("XYZ")? How is cacheManager implemented?
– Dan Wilson
Jul 2 at 13:22


cacheManager.Get("XYZ")


cacheManager





Put the two calls in separate lines. Right now you have no way of knowing what's causing that 100% CPU - deserialization or cacheManager.Get ?
– Panagiotis Kanavos
Jul 2 at 13:22


cacheManager.Get





Besides, given that almost all machines are multicore now, the only way to get 100% CPU is to flood all cores. DeserializeObject is not a parallel operation. Most likely cacheManager.Get causes a race condition forcing all cores to hit 100%. A blocking or locking operation can do that nicely, since blocking typically starts with a spinwait. That's not a bug of the runtime either - locks are supposed to be short lived. Rescheduling a thread is very expensive so it makes perfect sense to start with a spinwait before putting the thread to sleep
– Panagiotis Kanavos
Jul 2 at 13:24



DeserializeObject


cacheManager.Get





The solution is to not block. Use eg a ConcurrentDictionary instead of a standard dictionary with locking.
– Panagiotis Kanavos
Jul 2 at 13:26


ConcurrentDictionary









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?