Skip to main content
Filter by
Sorted by
Tagged with
-1 votes
1 answer
74 views

When I use gdb to debug futex locks with output, the program gets stuck in a weird loop. #include <mutex> #include <iostream> #include <thread> #include <unistd.h> volatile int ...
deadpool's user avatar
1 vote
0 answers
118 views

I'm thinking about how I would theoretically implement a multi threaded queue from first principles, using only glibc on POSIX. Obviously, this is going to require a mutex (or some other locking/...
ijustlovemath's user avatar
-1 votes
1 answer
160 views

I want to implement two different structures that have references to each other, can mutate each other, and are thread-safe. I can introduce the following example: pub struct Player { pub x: f32, ...
Vladimir Alinsky's user avatar
1 vote
1 answer
92 views

I'm currently reading a book called C++ concurrency in action. There is an example of spinlock mutex impl: class spinlock_mutex { std::atomic_flag flag; public: spinlock_mutex(): flag(...
lips106's user avatar
  • 11
2 votes
0 answers
100 views

The webrtc repository has an internal sample application, named sample_test_webrtc (the folder's name where it's implementation resides). I built it using gn and ninja and it works. Then I took that ...
Stefan Cosmin's user avatar
-1 votes
1 answer
327 views

myDlg = new Dlg(doc, myDlg , myDlgID); myDlg -> Create(myDlgID, this); myDlg -> ChangeFolder(directory); In the ChangeFolder function I use things, which are normally created only in ...
MieszkoPasierbek's user avatar
0 votes
1 answer
71 views

// Thread-safe Queue template<class T> class BlockingQueue { public: BlockingQueue() { isempty.lock(); } void push(T obj) { std::lock_guard<...
Schon's user avatar
  • 31
0 votes
0 answers
62 views

I'm working on a multi-threaded C program that simulates a supermarket with restocking and potentially customer behaviors (currently commented out). The program involves several threads representing ...
wesam's user avatar
  • 19
0 votes
1 answer
291 views

I'm encountering persistent data race warnings in my C++ parallel program despite using mutexes. I've implemented a solution using OpenMP and mutexes to synchronize access to shared data, but I ...
james dilaw's user avatar
2 votes
1 answer
152 views

The tokio::sync::mutex documentation mentions the following: Contrary to popular belief, it is ok and often preferred to use the ordinary Mutex from the standard library in asynchronous code. This ...
AsynCrony's user avatar
0 votes
1 answer
226 views

I have a condition variable std::condition_variable my_cond; I want to be able to replace boost::timed_wait() with an std equivalent one. If the previously mentioned condition variable was a boost one,...
user1584421's user avatar
  • 3,933
1 vote
1 answer
152 views

I have a question about thread safety and mutex locks in C++. I know that at the simplest level, a mutex lock should be held at any point where there could be simultaneous reading and writing to the ...
4-bit's user avatar
  • 274
1 vote
1 answer
132 views

I am working on a programming task that takes in an n value and uses three threads to print zero, even and odd numbers. For example, if n = 3, it will print 010203. I encountered a strange behavior ...
Der Fänger im Roggen's user avatar
0 votes
0 answers
125 views

I am looking for some clarity on the necessity to lock a variable if std::atomic<> is used on it. Please consider the following code: std::atomic<int> my_integer; void Thread1() { if (...
EmbeddedDOOD2's user avatar
-2 votes
2 answers
2k views

I have code that is something like this: var lock sync.Mutex func DoSomething() { lock.Lock() go func() { defer lock.Unlock() // Code here }() } func Wait() { lock.Lock() lock....
Dan Jones's user avatar
  • 1,460
2 votes
1 answer
235 views

It seems to me that if a data structure requires a lock for its contents to be accessed, then it doesn't matter what sort of data structure is inside. Even if the stuff on the inside is not thread ...
QuantumDot's user avatar
8 votes
1 answer
377 views

I implemented Morris's algorithm for a no-starve mutex from the Little Book of Semaphores (page 85) almost verbatim. About half the time, it terminates correctly, and the other half it freezes up mid-...
Phil's user avatar
  • 81
0 votes
0 answers
252 views

In my project I'm returning a std::scoped lock to guard some resources. A very simple example is this // Type your code here, or load an example. #include <mutex> class A { public: ...
JuliusCaesar's user avatar
  • 1,041
1 vote
0 answers
86 views

Running mBed OS on a B-L475E-IOT01A1 board but currently not using any threads or Mutexs. I borrowed an example test script to isolate the bit of code not working, shown below. This just reads and ...
Jonathan wheadon's user avatar
2 votes
0 answers
34 views

I'm doing an exercise for an exam, which asks me to create 2 processes (parent and child), each one must create N threads (N is provided by user) and a file (also the filename is provided by user). ...
Vanack Sabbadium's user avatar
1 vote
1 answer
69 views

I want that whenever there is switch on the file, My go routine reads from the new file. and for that I am using Mutexes to do so. But the output does not seem to be as expected. In f1.txt I have ...
Contour Free's user avatar
1 vote
0 answers
63 views

I've got a very time critical simulator that is supposed to run as fast as humanly possible. I tried to increase the data throughput by distributing every data frame to multiple worker threads. To ...
itzFlubby's user avatar
  • 2,287
0 votes
1 answer
134 views

I'm facing a problem using mutexes in two different threads. I have two thread functions: a producer, which receives data from the user and writes it to a global variable, and a consumer, which ...
Timur Khalikshin's user avatar
-1 votes
2 answers
278 views

Can we just put shared_mutex under the same header file, rather than a separate <shared_mutex> header file? When I use shared_mutex, I thought I only need to #include <mutex>. It turns ...
Dengzhi Zhang's user avatar
-1 votes
1 answer
53 views

The goal: The usp_prepare_data SQL Server stored procedure should check whether the requested data is prepared or not. If the data is ready to be used, the usp_prepare_data should return quickly. If ...
pepr's user avatar
  • 21.1k
2 votes
1 answer
594 views

I'm trying to translate a C++ program that uses a Bank object, with methods that change an account's balance and uses mutexes so this can happen in parallel. In this program, each account had a lock I ...
Naginipython's user avatar
0 votes
0 answers
101 views

I want to perform a join on three files and as a last step, I have to compute a sum from a certain column of the joined file. Let's say this is the part of the code where I read the last file line by ...
geekyDuck's user avatar
3 votes
1 answer
1k views

Suppose I have an application with multiple threads that need to access some shared data. I know that a mutex (Critical Section) can be used to ensure that at most one thread at a time can access the ...
William Cole's user avatar
0 votes
0 answers
434 views

I am developing on .net Framework 4.8 with LiteDb 5.0.17.0. When I try to instantiate a database connection with: Connection = new LiteDatabase("Filename=C:\\temp\\data.ldb;Connection=Shared"...
stigzler's user avatar
  • 1,035
-1 votes
1 answer
149 views

Is it legal to lock the std::mutex in main thread and then unlock in the child thread. Here is a demo snippet, which seems work. #include <iostream> #include <mutex> #include <thread>...
John's user avatar
  • 3,574
1 vote
1 answer
360 views

I'm learning about multi-threading in C# and found out that the Mutex class, can help me to synchronize threads working. So, I want to use the ThreadPool (limited to 10 threads) and this thread's ...
ViktorCode's user avatar
-2 votes
2 answers
88 views

is it possible that g_count++ is executed before init work is finished? ( I mean, maybe the complier or cpu would change their execution order ) #include <iostream> #include <mutex> #...
shaunwick's user avatar
0 votes
1 answer
139 views

I'm trying to do the following assignment: You will write a program that creates three threads. These threads access a shared integer, buffer, one at a time. The buffer will initially be set to 0. ...
Pablo's user avatar
  • 95
0 votes
0 answers
17 views

I have 2 threads running after write_fd was initialized by a call to pipe(): static bool finished = false; Thread 1 pthread_mutex_lock(&lock); if (!finished) { write(write_fd, buf, buf_len); }...
Itay Bianco's user avatar
0 votes
1 answer
423 views

I need some help for following case: I have a main program that starts multiple instances of the same function as threads. The function that gets called is split in at least two parts. First, every ...
TommyBe's user avatar
  • 11
-7 votes
4 answers
761 views

With RAII, we have std::unique_lock and std::scoped_lock. Those two are explicitly movable. RAII objects are "locked" when constructed and "unlocked" when destructed. So, I see ...
André Caldas's user avatar
0 votes
2 answers
217 views

I have this little simple queue where a one task read from a file into the queue and several tasks unpack the content. I works for a while, but eventually crashes because the queue is empty even ...
Suno's user avatar
  • 3
2 votes
0 answers
195 views

I have a data structure with: Multiple items 'A'. Each A has multiple items B. Each B is linked to exactly 1 A. Each B has multiple items C. Each C is linked to exactly 1 B. For a local search ...
Aedoro's user avatar
  • 940
6 votes
1 answer
695 views

I'm testing edge cases with std::condition_variable and I tested scenario to starve one thread. Scenario is that there are 99 producers and only one consumer, all of them working on 1 queue with max ...
Piwniczne's user avatar
1 vote
0 answers
473 views

Here is producer and consumer problem implementation with c++20 semaphore adapted from wikipedia https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem. Do we still need std::lock_guardstd::...
Dengzhi Zhang's user avatar
1 vote
0 answers
83 views

I am building an application using Rust + Iced. I have various services for creating and manipulating my data. As of now I have one struct that contains all of the services and I pass it around as ...
stove's user avatar
  • 576
0 votes
0 answers
42 views

My program has this function: 1 thread for vehicle moving and 1 thread for user_input and 1 thread for using that input to move the people. And after 1 step, I will draw the vehicle and people. If I ...
HCMUSer's user avatar
  • 27
0 votes
1 answer
77 views

Sometimes it does not wait long enough. I probably missed something simple - but I cant find it. Why from time to time wait function is returning prematurely #define SEMAPHORE_MAXWAIT -1 #define ...
0___________'s user avatar
  • 71.6k
1 vote
1 answer
70 views

I was trying to make three threads that each open a different input file, read a single character from it and set it to a global variable and then wait for the next thread to read a single character ...
brocoli's user avatar
  • 33
0 votes
1 answer
184 views

My assignment provides running code that uses a high percentage of the CPU when running. The goal is to reduce that amount by implementing conditional variables in the producer consumer problem. I ...
Samuel Afon's user avatar
-1 votes
1 answer
89 views

I have 2 methods TIC and TAC which just output "TIC" or "TAC". And my goal is after creating multiple threads of TIC and TAC. Final result should be: TIC TAC TIC TAC TIC TAC Here i ...
Yurii Salyha's user avatar
-2 votes
1 answer
117 views

I want to implement a lazy static reqwest::ClientBuilder. NB this is for a utilities module, so I have a feeling it'd be difficult to avoid using a static in this case. I want to construct it once, ...
mike rodent's user avatar
  • 16.1k
4 votes
1 answer
204 views

struct X { std::mutex m; std::string str; void set(std::string s) { auto _ = std::unique_lock(m); str = std::move(s); } ~X() { // auto _ =...
Anton Dyachenko's user avatar
3 votes
2 answers
128 views

Suppose we have some function which takes in a key, retreives its value from a shared hashtable, and perform some operations on it to obtain a new value , and then updates the hashtable with this new ...
Lew Wei Hao's user avatar
0 votes
1 answer
220 views

I am managing some per-customer data in a thread-safe way as follows: customer_id_to_data: Arc<RwLock<HashMap<CustomerId, Arc<RwLock<CustomerData>>>>> It's very important ...
gmoss's user avatar
  • 997

1 2 3
4
5
97