| | |
| | | |
| | | void test1() { |
| | | unsigned int i = 0; |
| | | int key = 2; |
| | | int key = -1; |
| | | |
| | | size_t qsize = 16; |
| | | void * queue = shmqueue_init( key, qsize, sizeof(message_t)); |
| | | void * queue = shmqueue_create( &key, qsize); |
| | | message_t item; |
| | | |
| | | for(i = 0; i < qsize; i++) { |
| | | sprintf(item.method, "hello"); |
| | | item.code = i ; |
| | | //入队 |
| | | if(shmqueue_push(queue, (void *)&item)) { |
| | | if(shmqueue_push(queue, (void *)&item, sizeof(message_t))) { |
| | | printf("push:%d %s\n", item.code, item.method ); |
| | | } |
| | | } |
| | | |
| | | printf("%d\n", key); |
| | | struct timespec timeout = {1, 0}; |
| | | |
| | | i = 0; |
| | |
| | | } |
| | | |
| | | //销毁队列 |
| | | shmqueue_destroy(queue); |
| | | shmqueue_drop(queue); |
| | | } |
| | | |
| | | |
| | | int main () { |
| | | mm_init(512); |
| | | test1(); |
| | | |
| | | //整个进程退出时需要执行这个方法,该方法首先会检查是否还有其他进程在使用该共享内存,如果还有其他进程在使用就只是detach,如果没有其他进程在使用则销毁整块内存。 |