Questions tagged [thread-synchronization]

In a multi-threaded environment thread synchronization is used to coordinate access to shared resources such as file handles, network connections, and memory

In a multi-threaded environment thread synchronization is used to coordinate access to shared resources such as file handles, network connections, and memory

References

645 questions
0
votes
2 answers

Thread scheduler in java with single CPU?

I have been reading that Thread scheduler in java runs only one thread at a time in a single process. Lets say that we have one JVM running one single CPU machine. So if I start 10 threads they will be managed by the same Thread scheduler. If one…
0
votes
1 answer

Can't access object on main thread

So my application does as follows: Main Thread: Create new object1, which starts Thread1 in its constructor. Instantiate object2, that contains a Vector3D and a AxisAngleRotation3D (among other things) Do things Thread1 tries to access…
mikepa88
  • 23
  • 4
0
votes
6 answers

Threading in Sequence

I am trying to learn how to write a program which performs a given set of tasks in sequence with the help of threads. For example, Writing a program which have 3 different threads print 1111…, 22222…., 333333……, so that the output will be…
sid
  • 129
  • 3
  • 11
0
votes
3 answers

Java execute 3 methods at same time inside custom method and grab values from run methods

I would like to execute 3 methods at same time in Java (obviously I need threads), and that I would like to execute not in separate class and not in my main method, but in my custom method. Can it be done? I have find this piece of code - Execute…
DarioBB
  • 663
  • 2
  • 8
  • 29
0
votes
1 answer

Is it necessary to synchronize I/O operation to MySQL

Is it necessary to synchronize input and output statements on MySQL? Database public class Database { private Object locker = new Object(); public boolean createUser(String username, String password) { …
Piotr K.
  • 95
  • 1
  • 2
  • 9
0
votes
1 answer

using threads on an Atomic Integer Array

I am writing code to let 4 threads build a histogram. I have an array in main: int N = 10000; Random r = new Random(); int[] a = new int[N]; for (int i = 0; i < a.length; i++) { a[i] = Math.abs(r.nextInt() % 100); } So basically what I want to…
John Doe
  • 31
  • 12
0
votes
4 answers

Thread synchronisation: Wait on two bool variables

I want to wait for two bool variables to be true in one thread. They are changed in different places. I can use boost in my project, but not C++11. I did find Info on how to use mutexes and condition variables, but im not sure if its possible to…
tzippy
  • 6,458
  • 30
  • 82
  • 151
0
votes
1 answer

Public final mutex for Java thread safety

In my project I have to use a class X which offers lots of methods, but the document doesn't mention if these methods are thread-safe, and I don't have the source code either. So I have encapsulated X in an other class with a mutex: public class MyX…
0
votes
0 answers

Executing threads concurrently

I am currently studying for my upcoming midterm and I am confused about this question which I have answered, but I am not completely sure if I answered it correctly: Given two threads: Initially x = 0 Thread 1: x = x+1 Thread 2: x = x + 2 What are…
Belphegor
  • 1,683
  • 4
  • 23
  • 44
0
votes
4 answers

Does ConcurrentHashMap need synchronization when incrementing its values?

I know ConcurrentHashMap is thread-safe e.g.putIfAbsent,Replace etc., but I was wondering, is a block of code like the one below safe? if (accumulator.containsKey(key)) { //accumulator is a ConcurrentHashMap accumulator.put(key,…
syfantid
  • 366
  • 5
  • 20
0
votes
1 answer

std::conditional_variable::notify_all does not wake up all the threads

I have a simple example here: The project can be called academic since I try to learn c++11 threads. Here is a description of what's going on. Imagine a really big std::string with lot's of assembly source code inside like mov ebx,ecx;\r\nmov…
0
votes
5 answers

Should I synchronize method in my example?

I'm not sure if I should synchronize method methodOne() in my example. I think not but I'm not 100% sure. Could you please give me advice what to do? public class SynchroIssue { class Test { private double a = 0; void methodOne() { …
0
votes
0 answers

Manipulate one big file with threads

I have a big file with sorted elements that looks like this a 1 1 a 2 1 a 3 5 b 2 3 b 3 5 ... I would like to create the inverted index of this file so it would look like this a 1 1 2 1 3 5 b 2 3 3 5 ... Now i have already done that. My…
Iraklis Bekiaris
  • 1,163
  • 15
  • 43
0
votes
1 answer

How to signal file HANDLE waiting with WaitForSingleObject

This code, which I have no control over, reads a file using overlapped I/O: // Read file asynchronously HANDLE hFile = CreateFile(..., FILE_FLAG_OVERLAPPED, ...); BYTE buffer[10]; OVERLAPPED oRead = { 0 }; ReadFile(hFile, buffer, 10, NULL,…
0
votes
1 answer

Python stuck in a single thread of a multi-threaded program

I'm currently writing a program that is attempting to synchronize a visitor, car, pump, and gas station thread at a zoo where guests arrive, wait for an available car, take a tour, then exit, the cars must refuel every 5 rides, and the gas station…