Re: Waking up a network server: 2 threads + semaphore vs 1 thread + pipe
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:references:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:mime-version :subject:date:cc:x-mailer; bh=CEcXG7kIZq/KU4VAVC5RyA1eRPwsViQUQxfZ8TEk23E=; b=lzetXVkdcdhPxSBdbCog2UYbjSFKnOWTzZmZ0E/6zLZffXX+rBiCOJn53HG7Ue9FNy K290l3IeCaUYcXz/0jJGaaqNw22byVrZQUFIzh6S059Vf65FJ66wDTxVXrl9xv+9lQao bMyAStDOti0TGL8Pch2VaifWrU1kkahNNYsug= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=references:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:mime-version:subject:date:cc:x-mailer; b=JC2THptaEkmzP+NMjlus4ZFhCQjG73VGNF62r925zzYnDu2I77Cv6fdvPg7eTvge4q XPkV0+6Ay7mz7CEG9/LURNlJqciyMh9bseMKiUtvJ59yXDWy7KBaaYEJFmTZxFmy5jzu 8lh2T3DV/RuS6Exc3cyrUNY2ECceAdHqBmimc= Terry, On Feb 14, 2009, at 2:19 PM, Terry Lambert wrote: My apologies. Certain experts are not on every list... like you. Which is the best design and how efficient? Thanks, Joel --- http://tinyco.de --- Mac & iPhone _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... Please do not crosspost, especially to subscription-required-to- reply lists. You've actually said almost nothing about your problem space, other than implying that the packets are network MTU sized or smaller by discounting UDP vs. TCP and therefore packet reassembly after fragmentation doesn't come into play.. I tried to give just enough background to make it suitable for the lists I was posting to. The problem space is real-time audio generation on the iPhone (VoIP or synthesized music) and the broadcast of said audio. The application is supposed to send, receive, mix microphone with generated audio and do it without stuttering. Imagine that the iPhone is an instrument and you are trying to put together a distributed orchestra. CoreAudio triggers a callback every few milliseconds to both ask for audio and to supply it. I'm using ring buffers to store generated audio and packets received from the network. I will need to invoke sendto (or CFSocketSendData) in a loop to deliver audio to clients but I don't think it's proper to do it from within the CoreAudio callback. I can wrap CFSockets around my native sockets and add them to the run loop but it seems from reading the source code that CFSocket may run a thread per socket. The "you can read" notification will be handled then and I'll just need to run a thread to iterate through my sockets and send the audio. I figure can wake up this thread from the CoreAudio callback by using a semaphore. Alternatively, I can track my sockets with select or kevent/kqueue and use the same mechanism to track a pipe and wake the sending thread. This will only require one thread since it will be woken up on both sends (byte put into a pipe) and receives. How efficient is it to put a byte into a pipe in a callback that gets triggered every few milliseconds? Would there be a significant gain since an extra thread is not required to wait on a semaphore? Would it even out since (intuitively) a pipe is slower? This email sent to site_archiver@lists.apple.com
participants (1)
-
Joel Reymont