So, my daemon is in terrible waters right now. I need help with getting it to at for one of two things to happen. First, I need to wait on libusb for events, either connects/disconnects or data (synchronous) and wait on a socket.

Now, the current idea is to make two threads that have blocking code that wait on each item. Each thread will kill the other when they finish, so waiting on one will let me know of some sort of event.

Second idea is to have the daemon run two threads, one for socket stuff and one for usb stuff. When one has an event, the other thread is suspended until the event is handled.

Any of these sound good? Other ideas I am not seeing?
What do you know about semaphores+mutexes?
Not much. I actually haven't used pthread before until just now, and haven't touched mutes and semaphores. Still trying to learn...
AHelper wrote:
Not much. I actually haven't used pthread before until just now, and haven't touched mutes and semaphores. Still trying to learn...


If you learn what they are, you'll be able to answer your own question. And by semaphore, I meant a counting semaphore, since mutexes behave very much like binary semaphores.

Also: http://en.wikipedia.org/wiki/Deadlock#Necessary_conditions
You should try reading The little book of semaphores if you need to learn more about them. The book is free so that should help some.
elfprince13 wrote:
AHelper wrote:
Not much. I actually haven't used pthread before until just now, and haven't touched mutes and semaphores. Still trying to learn...


If you learn what they are, you'll be able to answer your own question. And by semaphore, I meant a counting semaphore, since mutexes behave very much like binary semaphores.

Also: http://en.wikipedia.org/wiki/Deadlock#Necessary_conditions
Rats, you beat me to the party. This is exactly what I was going to suggest. Smile Unfortunately, the TI-83+ lacks an atomic TAS instruction natively, but if you're clever with interrupts, you can easily emulate it.
KermMartian wrote:
elfprince13 wrote:
AHelper wrote:
Not much. I actually haven't used pthread before until just now, and haven't touched mutes and semaphores. Still trying to learn...


If you learn what they are, you'll be able to answer your own question. And by semaphore, I meant a counting semaphore, since mutexes behave very much like binary semaphores.

Also: http://en.wikipedia.org/wiki/Deadlock#Necessary_conditions
Rats, you beat me to the party. This is exactly what I was going to suggest. Smile Unfortunately, the TI-83+ lacks an atomic TAS instruction natively, but if you're clever with interrupts, you can easily emulate it.

Daemon as-in a daemon on Linux, not a calc Smile

Also, thanks for the link, I will look at it soon.

<edit>

I added in mutexes, made 2 threads with infinite loops, and made all functions block. Now it runs much better, no cpu usage when nothing is going on Very Happy
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement