.\" This manpage is Copyright (C) 2016 MongoDB, Inc. .\" .\" Permission is granted to copy, distribute and/or modify this document .\" under the terms of the GNU Free Documentation License, Version 1.3 .\" or any later version published by the Free Software Foundation; .\" with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. .\" A copy of the license is included in the section entitled "GNU .\" Free Documentation License". .\" .TH "MONGOC_CLIENT_POOL_T" "3" "2016\(hy10\(hy12" "MongoDB C Driver" .SH NAME mongoc_client_pool_t \- Connection pooling abstraction .SH "SYNOPSIS" .nf .nf typedef struct _mongoc_client_pool_t mongoc_client_pool_t .fi .fi .B mongoc_client_pool_t is the basis for multi\(hythreading in the MongoDB C driver. Since .B mongoc_client_t structures are not thread\(hysafe, this structure is used to retrieve a new .B mongoc_client_t for a given thread. This structure .B is thread-safe . .SH "EXAMPLE" .nf #include static void * worker (void *data) { mongoc_client_pool_t *pool = data; mongoc_client_t *client; do { client = mongoc_client_pool_pop (pool); /* * Do something with client. If you are writing an HTTP server, you * probably only want to hold onto the client for the portion of the * request performing database queries. */ mongoc_client_pool_push (pool, client); } while (!inShutdown); return NULL; } int main (int argc, char *argv[]) { mongoc_client_pool_t *pool; mongoc_uri_t *uri; pthread_t thread[10]; unsigned i; void *ret; mongoc_init (); uri = mongoc_uri_new ("mongodb://mdb1.example.com/?minPoolSize=16"); pool = mongoc_client_pool_new (uri); for (i = 0; i < 10; i++) { pthread_create (&thread, NULL, worker, pool); } mongoc_uri_destroy (uri); for (i = 0; i < 10; i++) { pthread_join (threads [i], &ret); } mongoc_cleanup (); return 0; } .fi .B .SH COLOPHON This page is part of MongoDB C Driver. Please report any bugs at https://jira.mongodb.org/browse/CDRIVER.