Could you please advise how 

```
sudo su - userb

```

translates into ansible ?

More specifically, I would like to login to linux server X as `usera` then become `userb` (with the command above), and then execute all the tasks defined in the playbook as `userb`

The following are configuration options in `ansible.cfg`:

```
sudo_user      = root
#ask_sudo_pass = True
#ask_pass      = True
#remote_user = root
#become=True
#become_method=sudo
#become_user=root
#become_ask_pass=False

```

An example task would be:

```
- name: "Create the version directory of app"
        remote_user: userb
        file: path="{{ app_dir }}/{{ app_version }}" state=directory owner=userb group=xxx

```

EDIT: please note that no sudo password is provided in order to become `userb`

```
usera@serverX:~> sudo su - userb
Last login: Fri Nov 17 15:46:48 CET 2017 on pts/1
-bash-4.2$ 

```
['https://Stackoverflow.com/questions/47354108', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4035529/']
I do not believe this is possible without adding some extra state and interfaces to your BlockingQueue.

Proof goes something like this. You want to wait until the reading thread is blocked on `pop`. But there is no way to distinguish between that and the thread being about to execute the `pop`. This remains true no matter what you put just before or after the call to `pop` itself.

If you really want to fix this with 100% reliability, you need to add some state inside the queue, guarded by the queue's mutex, that means "someone is waiting". The `pop` call then has to update that state just before it atomically releases the mutex and goes to sleep on the internal condition variable. The `push` thread can obtain the mutex and wait until "someone is waiting". To avoid a busy loop here, you will want to use the condition variable again.

All of this machinery is nearly as complicated as the queue itself, so maybe you will want to test it, too... This sort of multi-threaded code is where concepts like "code coverage" -- and arguably even unit testing itself -- break down a bit. There are just too many possible interleavings of operations.

In practice, I would probably go with your original approach of sleeping.
You can use a `std::condition_variable` to accomplish this. The help page of cppreference.com actually shows a very nice cosumer-producer example which should be exactly what you are looking for: <http://en.cppreference.com/w/cpp/thread/condition_variable>

EDIT: Actually the german version of cppreference.com has an even better example :-) <http://de.cppreference.com/w/cpp/thread/condition_variable>