Questions tagged [shared-variable]

A shared-variable is used within multi-threaded software as the name implies; a variable that is shared between threads and in the context of thread safety and using mutexes in mind.

A variable that is to be used by multiple threads or processes. For instance, a variable that can be read by one thread and written to by another within the same program.

42 questions
1
vote
1 answer

How can I access methods of a class that is passed as argument to another class in python

I want to create a class(say, LockedAttributes) to access(READ/WRITE) some attributes safely by multiple threads.I want to pass those attributes that I want to share as a list to the LockedAttributes class. Some of the list elements are itself class…
1
vote
1 answer

javafx thread synchronization while true

I'm new to JavaFX and have some trouble with threads. My application has to do something like this (hard pseudocode): start(){ startLoop(); //new thread displayThingsSavedToSharedVariable(); } loop(){ while (true){ doThings(); …
1337_
  • 23
  • 4
1
vote
2 answers

Multiprocess with shared variable in bash

I'm trying to achieve a dynamic progress bar in bash script, the kind we see when installing new packages. In order to do this, a randomtask would call a progressbar script as a background task and feed it with some integer values. The first script…
1
vote
0 answers

Unpickable object - sharing and proxy object creation

I have a class Inner which cannot be pickled, and a class Outer which holds an instance of Inner which I want to share between processes, via pipe or queue. I was not able to do so because of the Inner class, so I tried creating a proxy object from…
Keren Meron
  • 139
  • 3
  • 14
1
vote
1 answer

Boost thread issue, how to share variable when one thread doesn't have the same copy as another?

This is probably a silly question but I did search all over the internet about variables and found everything related to mutexes and racing conditions, locks, etc; but nothing that seems to solve this simple problem. Basically the code below create…
pandoragami
  • 5,387
  • 15
  • 68
  • 116
0
votes
0 answers

How to unblock a Multiprocessing Queue for live-aggregation In Python

Here is a multiprocessing workflow with many consumers that execute tasks from a manager.queue. I use one extension Consumer of the multiprocess.Process class that runs Task which includes most of the runtime, and Aggor which runs all the time and…
0
votes
0 answers

dotnet C# Share variables across multiple instances of the same program

I am writing a program in C#. First, it reads a large file into a dictionary variable, then the variable is used as a search table to process other data (saved in another file). I would like to execute multiple instances of the program to process a…
DiabloRex
  • 1
  • 1
0
votes
1 answer

Should I use notify() instaed of notifyAll() in this case?

I was thinking about this code: public class SharedVariable { private T value; public SharedVariable(T init){ this.value = init; } public synchronized void testAndSet(Predicate p, T value) throws…
0
votes
1 answer

Python multiprocessing, how to return variables for a process that can be cancelled

I started from a tkinter app with a button starting a specific method from which data could be plotted with matplotlib on the gui. However I needed to be able to cancel that method, so I changed up the code to use multiprocessing, which worked as…
0
votes
1 answer

How to sync shared variables using Locks accessed by two Net6 Worker services?

IHost host = Host.CreateDefaultBuilder(args) .ConfigureServices(services => { services.AddHostedService(); services.AddHostedService(); }) .Build(); await host.RunAsync(); In VS2022, inside…
Walker66
  • 103
  • 10
0
votes
2 answers

Share local variable value between barrier threads in java

I've been working on implementing a custom Cyclic Barrier which adds values passed into the await method and returns the sum to all threads when after notify is called. The code: public class Barrier { private final int parties; private int…
0
votes
1 answer

Shared Variable in pthread

#include #include #include struct Arg1{ int x,y; }; void * process(void * threadarg){ int x,y; Arg1 * myArg1; myArg1 = (Arg1 *) threadarg; x = myArg1->x; y=myArg1->y; int i=0; …
levio_sa
  • 123
  • 9
0
votes
1 answer

python mutiprocessing on windows using shared values

I am trying to gain an insight into using multiprocessing with python. I have an example of using shared values for Unix but I cannot get a simple educational example to work on Windows 10. I have the code below running ok on Windows but with the…
ken205726
  • 21
  • 5
0
votes
1 answer

How to import a shared variable in two separate scripts?

I have the following simplified python code: myproject ├── main.py ├── shared_var.py └── utils.py shared_var.py: FOO = 'INIT' utils.py import time from shared_var import FOO def func_b(): global FOO print('func_b initial FOO value: ',…
Kid_Learning_C
  • 2,605
  • 4
  • 39
  • 71
0
votes
0 answers

Python Multiple Threads with a shared variable

I think this question is trivial but I'm having difficulty interpreting similar questions on here. I have multiple threads processing my data sequentially using queuing. That works fine, but I also would like to have a global configuration variable…