• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Is it thread safe ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Is it thread safe ?


  • Subject: RE: Is it thread safe ?
  • From: Pranav Kumar Sahu <email@hidden>
  • Date: Thu, 10 Apr 2003 11:07:26 +0530

I am developing a library which will deal with asynchronous calls for socket
API's.
I had done using CFSocket and CFRunLoop. When user(any client of library)
calls send or receive,
my library will keep required data in a global structure(specific to my
library).Then it will attach a CFSocket
and returns to client. When my callback gets called I will get proper data
and will call send or receive.

Now if i got multi-threaded client, I have to synchronize data and have to
keep track of the threads.
Since I have CFRunLoop, I don't need to know which thread's callback will
get called when data arrives right ?

For data synchronization I am thinking of removing globals. When client
makes a asynchronous call I am attaching a CFSocket
to it. I feel I can attach data too. If I can, I do not have to take care of
synchronization issues.
And my library will work irrespect of any client(Single or multi threaded).

Is this the right approach what I am thinking ?

Rgds
--Pranav


-----Original Message-----
From: Chris Hanson [mailto:email@hidden]
Sent: Wednesday, April 09, 2003 8:35 PM
To: Pranav Kumar Sahu
Subject: Re: Is it thread safe ?


At 12:50 PM +0530 4/9/03, Pranav Kumar Sahu wrote:
> I am using CFSocket for callback mechanism. In existing design i
>have data send through global structures. Now i am moving to multithreading
>environment. I was able send data by attaching CFSocketContext to my
>CFSocket. Is it thread safe ?

You're trying to use networking for inter-thread communication? Why?

Why not just use normal inter-thread communication mechanisms like
shared message queues? They're easier to write, easier to debug, and
easier to maintain in the future.

If you've never written multithreaded code before, I suggest reading
a good book on the subject and reading some example code before just
trying to hack something together. Just hacking together threaded
code is a good way to write code that has race conditions, priority
inversions, deadlocks, stale data, etc.

-- Chris

--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Application Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • RE: Is it thread safe ?
      • From: Quinn <email@hidden>
  • Prev by Date: Re: Creating multiple OT Contexts
  • Next by Date: Re: Identifing port names for users
  • Previous by thread: Re: Is it thread safe ?
  • Next by thread: RE: Is it thread safe ?
  • Index(es):
    • Date
    • Thread