• 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: Help with threads and queues
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with threads and queues


  • Subject: Re: Help with threads and queues
  • From: Dave DeLong <email@hidden>
  • Date: Thu, 29 Apr 2010 09:04:32 -0600

You'll basically be writing a custom object to wrap an NSArray in an object with a semaphore to make it threadsafe. Arrays are not threadsafe by default.

Cocoa doesn't have a semaphore object beyond the NSLock mutex. However, you can find an implementation of a semaphore here:

http://cocoaheads.byu.edu/wiki/locks

If you need more info, I can write more later when I'm not pecking at keys on a 2" screen.

Dave

Sent from my iPhone

On Apr 29, 2010, at 6:26 AM, PaulFranz <email@hidden> wrote:

> I am trying to convert my Java code to Objective-C code and I have run
> into a problem. I have thread, that currently has a socket open and it
> sits there and send packets of information through the socket.
> Currently my queue code uses the wait/notifyAll methods in Java to put
> the thread into a wait state (i.e. not actively checking and using
> CPU) and to wake it up. The methods look like:
>
> void push (String str)
> {
>   queue.add(str);
>   notifyAll();
> }
>
> String pop ()
> {
>  while (queue.isEmpty())
>     {
>     wait();
>     }
>
>  return queue.remove();
> }
>
> How do you do the samething in Cocoa/Objective-C?
>
> PaulFranz
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Help with threads and queues (From: Paul Franz <email@hidden>)

  • Prev by Date: Help with threads and queues
  • Next by Date: Re: Scripting Bridge for GUI scripting?
  • Previous by thread: Help with threads and queues
  • Next by thread: Re: Help with threads and queues
  • Index(es):
    • Date
    • Thread