Questions tagged [atomic-values]

Anything related to atomic values, i.e. values on which accesses and updates are guaranteed to happen atomically, that is without being interrupted by another thread of execution.

Anything related to atomic values, i.e. values on which accesses and updates are guaranteed to happen atomically, that is without being interrupted by another thread of execution.

13 questions
17
votes
4 answers

AtomicIntegerArray vs AtomicInteger[]

Is there any difference in meaning of AtomicIntegerArray and AtomicInteger[]? And which one is faster to use? (only thing that I noticed is that first is taking much less space, but that means that each recheck is checking boundaries of array, so…
Sarmun
  • 2,378
  • 2
  • 22
  • 24
5
votes
5 answers

Parallel version of loop not faster than serial version

I'm writing a program in C++ to perform a simulation of particular system. For each timestep, the biggest part of the execution is taking up by a single loop. Fortunately this is embarassingly parallel, so I decided to use Boost Threads to…
3
votes
2 answers

Is it good idea to use atomic boolean in kotlin?

Hey I am learning in atomic in kotlin. I am wondering is this good idea to use atomic boolean in my scenario? Can someone suggest, how to do in atomic way. Scenario 1 Not for first time call var isFirstTime = true fun notForFirstTime(){ …
Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127
2
votes
1 answer

single-reader single-writer fix-sized ringbuf, without lock and atomic variable, is it always safe for any CPU arch?

Was asked to wrap a blocking call to non-blocking during an interview today. So we (the interviewer and me) decided to achieve that by adding a background thread inside the nonblocking API. Here is the code I wrote: 30 #define ARRAY_SIZE(x) …
1
vote
1 answer

SCHEME remove atomic value from a list

I need to do a function where I send a value, and check in the list if there is an equal value to remove it. Here are some examples: (elimina 1 '(a b c)) => (a b c) (elimina 'b '(a (b) c)) => (a () c) (elimina 1 '(0 (1 (2) 1) 0))…
1
vote
2 answers

how to use an atomic vector as a string for a graph title in R

I'm trying to plot a graph from a matrix of z-scores in R, i would like to build a function to iterate through each column using the column header as part of the title and saving each graph as a png.I think I know how to do the iteration and saving…
user3062260
  • 1,584
  • 4
  • 25
  • 53
1
vote
2 answers

How can I structure a table so that the field remains atomic?

I have a shopping cart in which I have to keep track of stock, and this includes stock with attributes. For example: shirt -- blue, small = 50 -- blue, medium = 22 -- blue, large = 53 -- red, small = 15 etc... These fields are currently…
xenon
  • 1,435
  • 19
  • 35
0
votes
2 answers

AtomicInteger not reading value from main memory for non-volatile mutable refrence

Below is a non-thread-safe implementation of popular Husband Wife bank account problem. (One thread first checks the account, and before the same thread performs withdraw, another thread performs withdraw operation, thus breaking the code). If we…
mogli
  • 1,549
  • 4
  • 29
  • 57
0
votes
2 answers

Java 8 variable should be final or effectively final issue

I am using Java 8 stream Iteration with a variable that should be used in other classes also. So I have used the below code. AtomicBoolean bool = new AtomicBoolean(true); public void testBool(){ list.stream().forEach(c->{ if( c.getName() !=…
Neela
  • 107
  • 2
  • 10
0
votes
1 answer

Error "$ operator is invalid for atomic vectors" despite not using atomic vectors or $

Hello fellow Stackers! This is my first question so i am curious if you can help me! :) First: I checked similar questions and unfortunately none of the solutions worked for me. Tried it for nearly 3 days now :/ Since I am working with sensitive…
0
votes
2 answers

Controlling an instance's state with AtomicBoolean

I need to ensure that a particular start and stop code is executed only once per instance lifecycle, and that the instance cannot be "restarted". Is the following code adequate for a scenario where multiple threads may be acting upon the…
Tony E. Stark
  • 445
  • 3
  • 13
0
votes
1 answer

Implementing an AtomicByteArray in Java using AtomicIntegerArray

I need an AtomicByteArray for a memory-critical application modeled after Java's AtomicIntegerArray. My implementation wraps four bytes into an integer and uses the AtomicIntegerArray. The get() implementation is trivial, and the and set()…
Shilad Sen
  • 114
  • 1
  • 10
-1
votes
2 answers

Why compiler forces to use Atomic variable inside forEach loop in java

I am trying to write a code to find min and max in an array when I write code using basic java I can use normal variable but when I use forEach loop complier forces me use atomic varaible.Why is it necessary to use atomic variable inside a forEach…