01110100110101010101011101100010
C
small epoll wrapper
Mar 13th
I remember my first encounter with epoll some time back trying to get a simple server working, implementing a proxy and then a few days back i saw one of my friend trying to get started with epoll, which made me think it will be good to have a simple wrapper around epoll which will allow me to get started with the application and not worry about epoll specifics and at the same time providing enough control, so i wrote a small wrapper with callbacks, which has been quite helpful for my epoll usage, here is the interface poll.h
code and a sample can be found on github
PS – just checkout libevent which is an awesome battle tested event notification library, and a quick getting started
Simple hash tables in c
Mar 11th
I was working on a code where i had to lookup a structure based on the file descriptor (socket) again and again in a code, i was using a linked list initially but as the nodes grew i knew i should use a hash table, so i wrote a simple hash table implementation which did the work.
its a just works implementation there are a lot of thing which can be added like a perfect hash function but as long as hash table is not the bottle neck this should work, code can be found on github
file hashtable.h contains the definition
More >
Simple Finite State Machines in C
Apr 5th
I was having discussion about State Machines with one of my friend, regarding pro’s and con’s of implementing programs as Sate Machines, it was then that i realised there is no simple way to implement programs as Finite State Machines, so here is a very basic implementation of FSM in C
file: fsm.h contains the function definition for our FSM
Getting started with pthread
Sep 25th
Recently i have started coding in C a lot and what i came across from a lot of people is that doing Threading in C is very hard, is it really like that? here is a simple Pthread program that should clear that up
get it here
in the above program i have just created 2 threads and passed thr1 ( = 1 ) and thr2 ( = 2 ) values as parameters the function void * thread ( void * ptr ) is executes as a separate thread, we create two thread objects thread1 and thread2, and start threads using pthread_create function passing thread object, function pointer and parameters as arguments, here NULL specifies default attributes for the thread, we can change this by passing pthread_attr_t structure instead of NULL.
we wait for the threads to finish using the pthread_join function
One major problem that is faced by most of the people is of using a library which is not a thread safe library, so you need to be careful about the libraries you use in your program, if not sure about a particular library being thread safe, just assume it not to be thread safe
PS – No updates from a long time as i dont have a proper net connection ….



