Sipdroid's Blog

Synchronized Age Map

Posted in c++ by sipdroid on April 19, 2010

I often need a synchronized map in multiple threads environment. developed a basic one , if  you have any comments to improve it, please let me know.


/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 pthread_mutexattr_t mutex_attr;
 pthread_mutexattr_init(&mutex_attr);
 pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
 pthread_mutex_init(&mutex_, &mutex_attr);
 // pthread_mutex_init(&mutex_, NULL);

Advertisements
Tagged with: