Synchronization vs Lock

java.util.concurrent API provides a class called as Lock, which would basically serialize the control in order to access the critical resource. It gives method such as park() and unpark(). We can do similar things if we can use synchronized keyword and using wait() and notify() notifyAll() methods. I am wondering which one of these is … Read more

Choose between ExecutorService’s submit and ExecutorService’s execute

How should I choose between ExecutorService’s submit or execute, if the returned value is not my concern? If I test both, I didn’t see any differences among the two except the returned value. ExecutorService threadExecutor = Executors.newSingleThreadExecutor(); threadExecutor.execute(new Task()); ExecutorService threadExecutor = Executors.newSingleThreadExecutor(); threadExecutor.submit(new Task()); 7 Answers 7

Is errno thread-safe?

In errno.h, this variable is declared as extern int errno; so my question is, is it safe to check errno value after some calls or use perror() in multi-threaded code. Is this a thread safe variable? If not, then whats the alternative ? I am using linux with gcc on x86 architecture. 8 Answers 8

The calling thread must be STA, because many UI components require this

I am using http://www.codeproject.com/KB/IP/Facebook_API.aspx I am trying to call the XAML which is created using WPF. But it gives me an error: The calling thread must be STA, because many UI components require this. I don’t know what to do. I am trying to do this: FacebookApplication.FacebookFriendsList ffl = new FacebookFriendsList(); But it is giving … Read more

Cross-thread operation not valid: Control ‘textBox1’ accessed from a thread other than the thread it was created on [duplicate]

This question already has answers here: Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on (23 answers) Closed 6 years ago. I want to send temperature value from a microcontroller using UART to C# interface and Display temperature on Label.Content. Here is my microcontroller code: while(1) { … Read more

Do spurious wakeups in Java actually happen?

Seeing various locking related question and (almost) always finding the ‘loop because of spurious wakeups’ terms1 I wonder, has anyone experienced such kind of a wakeup (assuming a decent hardware/software environment for example)? I know the term ‘spurious’ means no apparent reason but what can be the reasons for such kind of an event? (1 … Read more

Redis is single-threaded, then how does it do concurrent I/O?

Trying to grasp some basics of Redis I came across an interesting blog post . The author states: Redis is single-threaded with epoll/kqueue and scale indefinitely in terms of I/O concurrency. I surely misunderstand the whole threading thing, because I find this statement puzzling. If a program is single-threaded, how does it do anything concurrently? … Read more

Java synchronized method lock on object, or method?

If I have 2 synchronized methods in the same class, but each accessing different variables, can 2 threads access those 2 methods at the same time? Does the lock occur on the object, or does it get as specific as the variables inside the synchronized method? Example: class X { private int a; private int … Read more