Posix pipe as a work queue

The usual work queue implementations I've seen are related to mutexes and state variables.

Consumer:

A) Acquires Lock
B) While Queue empty
      Wait on Condition Variable (thus suspending thread and releasing lock)
C) Work object retrieved from queue
D) Lock is released
E) Do Work
F) GOTO A

Manufacturer:

A) Acquires Lock
B) Work is added to queue
C) condition variable is signaled (potentially releasing worker)
D) Lock is released

I was looking at some code, and I saw an implementation using POSIX pipes (I had not seen this before).

Consumer:

A) Do select on pipe (thus suspending thread while no work)
B) Get Job from pipe
C) Do Work
D) GOTO A

Manufacturer:

A) Write Job to pipe.

Since the producer and the consumer are flows within the same application (thus, they have the same address space and, therefore, the pointers between them are valid); tasks are written into the pipe as the address of the working object (C ++ object). Thus, all that needs to be written / read from the channel is an 8-byte address.

My question is:

  • Is this a common technique (I am protected from this) and what are the advantages / disadvantages?

, ( ). , ?

Edit:

@Maxim .

, "" - . , , , , "".

+5
4

, , - (.. , select/epoll), - , -.

, , . .

/ , , , - epoll ( , , /). , /, , , , / . , Linux eventfd -.

+3

. , .

, , , , , select().

+1

, , , , . , , .

, .

EDIT: , , .

: . , ...

0

select , .

select() pselect() , , "" - (, ). , - (, (2)) .

- ", FD ". .

0

All Articles