1

I have a few of threads in charge of the communication sessions respectively. Each of them will execute a small piece of code, that just copys a struct into a queue(one que for one thread, for lock-free), when they receive some data.

I don't want they be suspended during enquing the data, so that I can ensure some consistency of timing(first received first enqued), as well as let this critical section(enquing) be executed as fast as possible.

I know it can be resolved with a lock and by using single queue for all threads, but I don't want some of them be blocked to wait for accquiring the lock.

Is there a way in c++ to resolve this issue? I'm using gcc-8.2.0 and stl in a linux box.

In the fact, I'm expecting a method, with it I can define a "critical-section" of codes. When threads are executing inside such section, they would never be suspended/blocked by OS.

Sorry for my poor English, hope I has expressed things correctly. Thanks!

Leon
  • 1,489
  • 1
  • 12
  • 31
  • 3
    This is more related to the os than the programming language. There are kernel API that can change the scheduling policy of a thread to be real time. For Linux see `man 7 scheduling` http://man7.org/linux/man-pages/man7/sched.7.html – Oliv Jan 26 '19 at 18:42
  • 1
    Perhaps what you are looking for is a *lockless* FIFO queue? It is supposed to guarantee that producers won't block (see: https://stackoverflow.com/questions/8918401/does-a-multiple-producer-single-consumer-lock-free-queue-exist-for-c ) – Jeremy Friesner Jan 26 '19 at 22:40

0 Answers0