Return-Path: william@bourbon.usc.edu Delivery-Date: Mon Oct 27 10:56:31 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m9RHuVL8022799 for ; Mon, 27 Oct 2008 10:56:31 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m9RI7Qlv011792 for ; Mon, 27 Oct 2008 11:07:26 -0700 Message-Id: <200810271807.m9RI7Qlv011792@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: Ok to call "normal" methods from "threaded" methods? Date: Mon, 27 Oct 2008 11:07:26 -0700 From: Bill Cheng Someone wrote: > Within the same file I have 'threaded' methods (for client, server, etc.) as > well as 'normal' methods (that are called normally, and not as individual > threads). The 'normal' methods are used simply to read/write from sockets > (id's passed as parameters) and do not access any shared variables. Could > calling these 'normal' methods from the 'threaded' methods possibly cause > any side effects? If your "normal" methods are "thread-safe", then they should not cause problems. Of course, supposed thread-safe methods or functions may not be actually thread-safe because there are bugs! Please remember that C and C++ are basically the same thing. Also, C functions and C++ methods are basically the same thing. The difference is that the corresponding C++ object is passed to C++ method as the first argument automatically and hidden from you. So, thread-safety applies the same way to C++ methods as they do to C functions. > I am seeing strange behavior from my threads around the times they call the > 'normal' methods (for example, seeming to block when they shouldn't be, > which causes my thread loops to simply not loop). Do you think it would be > better to include the code from the 'normal' methods directly into > 'threaded' methods, rather than separating them out? I don't think it would make any difference if there are bugs in these methods! -- Bill Cheng // bill.cheng@usc.edu