# Multiple threads writing to the same Starling queue doesn't work?

**URL:** <https://www.ruby-forum.com/t/multiple-threads-writing-to-the-same-starling-queue-doesnt-work/189538>\
**Category:** Rails\
**Created:** [June 2, 2010, 6:40pm UTC](https://www.ruby-forum.com/t/multiple-threads-writing-to-the-same-starling-queue-doesnt-work/189538 "2010-06-02T18:40:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PierreW](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@PierreW](https://www.ruby-forum.com/u/PierreW)\
**Post date:** [June 2, 2010, 6:40pm UTC](https://www.ruby-forum.com/t/multiple-threads-writing-to-the-same-starling-queue-doesnt-work/189538/1 "2010-06-02T18:40:36Z")

</div>

Hi guys,

I can’t find a clear answer to this: is it possible/correct to have  
several threads write to the same Starling queue at the “same time”?

It doesn’t seem reliable according to my tests - but maybe I am doing  
something wrong.

If I do:

def test\_starling

FooWorker.asynch\_foo\_test(:my\_id =\> ‘foo’)  
temp = []  
for i in 1…1000  
temp \<\< Thread.new(i) {|random\_value| do\_stuff(random\_value)}  
end

temp.each do |t|  
t.join  
end  
end

def do\_stuff(lvalue)  
starling = Starling.new(‘localhost:22122’)  
starling.set(‘foo’, :rvalue =\> lvalue)  
end

# In FooWorker:

def foo\_test(options)  
starling = Starling.new(‘localhost:22122’)  
while true  
temp = starling.get(options[: my\_id].to\_s)  
puts temp.inspect  
end  
end

Some of the queue values don’t get output to the console (randomly).

I could get it to work with a mutex but it doesn’t seem right to me -  
there should be a way to do that without having to lock the queue?

Thanks,  
Pierre
