# Multithreading sysread error

**URL:** <https://www.ruby-forum.com/t/multithreading-sysread-error/131022>\
**Category:** Ruby\
**Created:** [March 5, 2008, 10:10am UTC](https://www.ruby-forum.com/t/multithreading-sysread-error/131022 "2008-03-05T10:10:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![learningruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6bbea6/32.png) [@learningruby](https://www.ruby-forum.com/u/learningruby)\
**Post date:** [March 5, 2008, 10:10am UTC](https://www.ruby-forum.com/t/multithreading-sysread-error/131022/1 "2008-03-05T10:10:28Z")

</div>

Hi All,

```
      I am a newbie at scraping and multi-threading too. Recently, I

```

have to implement these two in one of my application. Please find my  
code in the attachment. I was facing some peculiar issues and the reason  
I don’t know!!! The code works pretty well on my ubuntu7.04 but throws  
some “sysread”, “read\_status\_line” errors when run on Windows. What  
could be the obvious problem? Any help greatly appreciated.

regards,  
Venkat B.

---

<div class="post-metadata">

**Author:** ![learningruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6bbea6/32.png) [@learningruby](https://www.ruby-forum.com/u/learningruby)\
**Post date:** [March 5, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/multithreading-sysread-error/131022/2 "2008-03-05T20:20:15Z")

</div>

There are a number of problems, among them:

1. deriving from Monitor does not do anything for you in  
this case, since you don’t use any of its locking  
facilities (deriving from Monitor like this probably  
isn’t a good approach anyway)

2. WWW::Mechanize instances are not safe to share  
between threads; it’s best to create a separate agent  
per thread.

3. Using the Timeout class on complicated libraries  
can often break them. If you really need operations  
to time out, it is best to see if the library provides  
direct support for timeouts on its operations.

-mental

---

<div class="post-metadata">

**Author:** ![learningruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6bbea6/32.png) [@learningruby](https://www.ruby-forum.com/u/learningruby)\
**Post date:** [March 5, 2008, 8:56pm UTC](https://www.ruby-forum.com/t/multithreading-sysread-error/131022/3 "2008-03-05T20:56:13Z")

</div>

On Wed, Mar 5, 2008 at 3:10 AM, Venkat B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Venkat B.  
> sysread uses a “low-level” read. In general, I wouldn’t be confident  
> that anything marked as “low-level” can be mixed well with  
> multi-threading. On my system, sysread is slower than ordinary read,  
> so I fail to see the advantage versus the standard IO#read.

Daniel Brumbaugh K.

---

<div class="post-metadata">

**Author:** ![learningruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6bbea6/32.png) [@learningruby](https://www.ruby-forum.com/u/learningruby)\
**Post date:** [March 10, 2008, 9:28am UTC](https://www.ruby-forum.com/t/multithreading-sysread-error/131022/4 "2008-03-10T09:28:29Z")

</div>

On Mon, 2008-03-10 at 15:21 +0900, Venkat B. wrote:

> I used a synchronized block in “download\_file(html\_link)”  
> method…Doesn’t that make any sense of locking ??? Am I wrong again !!!

In the code you gave, shared resources like @@html\_links and @agent  
aren’t protected at all.

-mental

---

<div class="post-metadata">

**Author:** ![learningruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6bbea6/32.png) [@learningruby](https://www.ruby-forum.com/u/learningruby)\
**Post date:** [March 10, 2008, 7:21am UTC](https://www.ruby-forum.com/t/multithreading-sysread-error/131022/5 "2008-03-10T07:21:36Z")

</div>

Mental G. wrote:

> There are a number of problems, among them:
> 
> 1. deriving from Monitor does not do anything for you in  
> this case, since you don’t use any of its locking  
> facilities (deriving from Monitor like this probably  
> isn’t a good approach anyway)

> -mental

I used a synchronized block in “download\_file(html\_link)”  
method…Doesn’t that make any sense of locking ??? Am I wrong again !!!
