answersLogoWhite

0

Thread synchronization requires that a running thread gain a "lock" on an object before it can access it. The thread will wait in line for another thread that is using the method/data member to be done with it. This is very important to prevent the corruption of program data if multiple threads will be accessing the same data. If two threads try to change a variable or execute the same method at the same, this can cause serious and difficult to find problems. Thread synchronization helps prevent this.

User Avatar

Wiki User

19y ago

What else can I help you with?

Related Questions

How does thread synchronization occur in a monitor?

by using synchronized class


What is thread synchonisation in os?

The thread synchronization is done for sharing of a common resource, to find the no. of resources in use, its count ,maximum resources in use... To establish this the various synchronization tools used are.. Events Waitable Timer


What is interprocess synchronization?

Processes might need to communicate to each. Interprocess of synchronization is the?æ management of resource among process. It ensures only a single thread (process) access a resource at a particular time.


What is dfference between synchronization and asynchronization in java with example?

synchornisation is the process where more than one thread can be accessed by accesssing the shared object of the class.By syncornisation we can have the communication between threads.if one thread works then another thread automatically stops


Synchronization in java?

Threads communicate primarily by sharing access to fields and the objects reference fields refer to. This form of communication is extremely efficient, but makes two kinds of errors possible: thread interference and memory consistency errors. The tool needed to prevent these errors is synchronization.


What is difference between synchronization and inter thread communication?

Synchronization is the process by which, access to the objects by threads are controlled and at at time only one thread can access an object. This is done to ensure that there are no dirty read/write operations. If multiple threads access the same data simultaneously, we may end up with inconsistent data. To avoid it, we place such code in synchronized blocks/methods to ensure integrity of data. Inter thread communication is the process by which java threads can communicate with one another. They communicate to one another through some commands like wait, notify, notifyall etc.


What are some strategies for resolving thread contention in a multi-threaded application?

Some strategies for resolving thread contention in a multi-threaded application include using synchronization mechanisms like locks, semaphores, and mutexes to control access to shared resources, implementing thread-safe data structures, reducing the scope of synchronized blocks, and using thread pooling to limit the number of active threads. Additionally, optimizing the design of the application to minimize the need for shared resources can help reduce thread contention.


When was Transactional Synchronization Extensions created?

Transactional Synchronization Extensions was created in 2012.


Why current is not concidered while synchronization?

current is load dependent,after synchronization only current will flow


What are examples of synchronization?

SONET


What is thread safety and synchronization?

Thread safety is a term that is applied to a language's ability to safely modify the same memory location concurrently in multiple processes. A language that does not have thread safety cannot guarantee program correctness. Synchronization is one of the most common means of offering thread safety. To understand thread safety, you must first understand multitasking. A program running multiple tasks (called threads) at once does not actually run all of the threads at the exact same time. Instead, each task takes up a small sliver of the CPU's total processing time, and when it reaches a stopping point, or when an amount of time has elapsed, it is suspended, set aside, and the next task gets a chance to run. This happens so quickly that users have the appearance of many things running at once. However, when two threads are trying to use the same memory resource, bad things can happen if they are interrupted at the wrong time. Consider these two threads: Thread 1: Load x. Add 5 to x. Store this result in x. Thread 2: Load x. Add 10 to x. Store this result in x. Now, if thread 1 runs before or after thread 2, there is no problem. However, if thread 1 is interrupted, you might see a bug: X = 0 Thread 1: Load X (0) into reg1 (0). Thread 1: Add 5 to reg1 (5). Thread 2: Load x (0) into reg2 (0). Thread 2: Add 10 to reg2 (10). Thread 2: Store reg2 (10) into x (0 -> 10). Thread 1: Store reg1 (5) into x (10 -> 5). In case you missed it, you'll see that if 10 and 5 are added to x, the total should be 15. However, thread 2 preempted thread 1 at a critical point, and so thread 2 was unaware that x should have been 5, not 0. Since thread 1 had no idea that thread 2 was going to preempt the processing at that time, it didn't know that X changed to 10, and thus clobbered thread 2's work when it resumed. In order to fix this, you add a synchronization lock. This prevents a thread from starting after a critical point until the critical point has passed. It would look like this: Thread 1: Lock x. Load x. Add 5 to x. Store x. Unlock x. Thread 2: Lock x. Load x. Add 10 to x. Store x. Unlock x. Now, the logic might look like this: Thread 1: Lock x. Thread 1: Load x. Thread 1: Add 5 to x. Thread 2: Lock x. (Cannot lock, so wait). Thread 1: Store x. Thread 2: Lock x. Thread 2: Load x. Thread 2: Add 10 to x. Thread 2: Store x. In this example, thread 2 was forced to wait on the other thread. While overall processing speed is reduced, the system successfully added the numbers in order without losing any results; x would be 15 after those two threads were done.


Explain why interrupts are not appropriate for implementing synchronization?

Because they are completely unrelated things? Synchronization can be implemented with semaphores or mutexes.