Tag Info

New answers tagged

0

Set some variable (accessible to your unit test) when the event occurs. If the event doesn't occur, the variable doesn't get set; you can check for that in your unit test.


0

There are many concurrency models so you'd better have a good idea about all before you decide which one to pick. For that, I recommend the book Seven Concurrency Models in Seven Weeks: When Threads Unravel. Check the reviews and the TOC and you can see why this is a good book. And it is also recent (2014).


0

To learn about concurrency, use a language that was designed for concurrency. Golang is a good choice since it has built-in support for concurrency and a C-like syntax which makes the language easy to learn for most programmers. It has message passing, mutexes etc which cover almost all of your concurrency needs and which have more complicated equivalents ...


4

Is the cache always rendered useless after a context switch? No, not at all. Context switches are actually a concept of the software that runs on a CPU, not one of the CPU itself. When the software decides to do a context switch, the state of the CPU is saved somewhere convenient, a new or previously-saved state is loaded and execution jumps to the ...


-1

Although most answers approach from the side of software and/or hardware model, the cleanest way is to consider how the physical RAM chips work. (The cache is located between the processor and the memory, and simply uses the same address bus, and its operation is completely transparent for the processor.) RAM chips have one single address decoder, which ...


0

I utilized the Producer Consumer design pattern for this implementation. So far the performance has been ideal. I am adding answer as StackCareer won't let me link to this post as a answer but my question was more of a confirmation. I am assuming this will get flagged :/


1

The best way to manage threads is to not do it. In C# we achieve concurrency without direct thread management by virtue of async/await, or sometimes (as mentioned by others) lambda expressions, most commonly via PLINQ. It is expensive, slow and subject to availability to start and stop threads. Instead, the above approaches use a pool of preallocated ...


0

Don't. It's not a static class, and they aren't static methods, so there's no reason why it shouldn't be up to calling code to avoid concurrent calls. With static methods, then you would have to do some of the work to make it handle concurrent calls because calling code can't guarantee that it is the only calling code. And of course with instance methods ...


24

I am making a little program, which have few Threads, constantly running. At some point, I may want to stop one of them, and then, after random period of time, to start it again. What is the best way to create a thread? The best way is to not do it at all. If I have work that needs to be done in parallel to another program, the best practice is to start ...


3

With regards to the two ways of starting the thread, they are roughly equivalent, so it is a matter of whether you prefer a lambda. For stopping the thread, the most error proof way is to check a field value for a change. This can be done using a memory barrier, for example, using a lock statement or a Monitor will automatically provide a memory barrier. ...


1

Don't reinvent the wheel. .NET Framework already has logging that you can easily use in your application. The logging framework will handle the multithreading for you (and TraceSource is thread-safe according the documentation). Under the hood, when the log file cannot be written (which is quite rare, since TraceSource uses a global lock internally, and ...


1

If one thread calls Add, and another thread calls Contains, at exactly the same time, and everything is implemented correctly, then Contains will return either the value that was correct before calling Add, or the value that was correct after calling Add. That's the best that we can expect. If you can implement both the Add and the Contains method in a way ...


0

You don't care about physical RAM, you care more about virtual memory and address space of processes or threads (all the threads of the same process share a common address space) in practice. Of course if you are coding a multi-core operating system kernel, you care about RAM and cache coherence a big lot. Most multi-core processors have some form of cache ...


-1

Modern CPUs are physically tied to their external memory devices in order to obtain maximum data transfer bandwidth. This is due to signal integrity requirements (trace length, termination, clock skew, etc) necessary to sustain the high transfer rates. For example, on a multi-CPU motherboard, each CPU has a dedicated set of DIMM slots. Regardless of what ...


0

This sounds like a pretty standard multi-threading problem which can be solved by well-established techniques. My suggestion would be: Set up a singleton class whose job in life is to log events. Synchronize the methods to ensure it is thread safe. Have each test regularly call the thread-safe logger to do any logging work. Make sure that the logging ...


2

It's about scheduling overhead, and about how some solutions fit specific problems better than others. Scheduling is the activity of deciding who is executing right now, and switching between processes/threads. Cooperative scheduling is simple to implement, and requires that each participating thread must yield to the scheduler when a sensible pause state ...


1

All thing being equal, user space will have fewer layer of abstraction to work through. OS thread will require relatively slow calls through the kernel. User space, done correctly will avoid these abstractions. This results in the opportunity for higher performance.


0

I once had a huge SGI IRIX environment. Just for the heck of it, I wrote a small multi-threaded java program(which just did nothing but consume CPU cycles) and created 12 threads in it. The job spanned across 12 CPUs in NUMA architecture. May be I will look up the program and run it on the Dell R910s and check..


4

You have no reason to assume how many CPU cores the users system has. You development machine might run on a 4-core CPU with nothing else to do, but it could also be moved to a single-core virtual machine or a 32-core high-end server. For that reason you should not hard-code the number of CPUs. In Java, you can use ThreadPoolExecutor's to delegate the ...



Top 50 recent answers are included