Esempio n. 1
0
int main()
{
  int i;
  pthread_t child[NUM_CHILDREN];

  Shared *shared = make_shared();

  child[0] = make_thread(producer_entry, shared);
  child[1] = make_thread(consumer_entry, shared);

  for (i=0; i<NUM_CHILDREN; i++) {
    join_thread(child[i]);
  }

  return 0;
}
void test_move_from_function_return()
{
    boost::thread::id the_id;
    boost::thread x=make_thread(&the_id);
    boost::thread::id x_id=x.get_id();
    x.join();
    BOOST_CHECK_EQUAL(the_id,x_id);
}
int main ()
{
  int i;
  pthread_t child[NUM_CHILDREN];

  Shared *shared = make_shared (100000000);

  for (i=0; i<NUM_CHILDREN; i++) {
    child[i] = make_thread (entry, shared);
  }

  for (i=0; i<NUM_CHILDREN; i++) {
    join_thread (child[i]);
  }

  check_array (shared);
  return 0;
}
Esempio n. 4
0
int cli_main( uint16_t port ) {
    struct sockaddr_in addr;
    struct sockaddr client_addr;
    int bindfd;
    int clientfd;
    cli_client_t* client;
#ifdef _STANDALONE_CLI_
    unsigned sock_len;
#else
    int sock_len;
#endif

    sock_len = sizeof(struct sockaddr);
    pthread_mutex_init( &parser_lock, NULL );

    cli_init();
    cli_parser_init();
    cli_scanner_init();

    /* create a socket to listen for connections on */
    bindfd = socket( AF_INET, SOCK_STREAM, 0 );
    if( bindfd == -1 ) {
        fprintf( stderr, "Error: unable to create a IPv4 TCP socket" );
        return CLI_ERROR;
    }

    /* bind to the requested port */
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = 0;
    memset(&(addr.sin_zero), 0, sizeof(addr.sin_zero));
    if( bind(bindfd, (struct sockaddr*)&addr, sizeof(struct sockaddr)) ) {
        fprintf( stderr, "Error: CLI unable to bind to port %u", port );
        return CLI_ERROR;
    }

    /* listen for clients */
    listen( bindfd, 10 );

#ifndef _STANDALONE_CLI_
    /* listen locally too */
    cli_local_init( port );
#endif

    while( !cli_is_time_to_shutdown() ) {
        /* wait for a new client */
        clientfd = accept(bindfd, &client_addr, &sock_len);
        if( clientfd == - 1 ) {
            if( errno == EINTR ) {
                /* Interrupt received, going back to accept() */
                continue;
            }

            /* some error */
            perror( "accept() failed" );
            continue;
        }
        /* accepted a new connection client */

        /* create a client record */
        client = malloc_or_die( sizeof(cli_client_t) );
        client->fd = clientfd;
        search_state_init( &client->state, CLI_INIT_BUF, CLI_MAX_BUF );

        /* spawn a new thread to handle the client */
        make_thread( cli_client_handler_main, client );
    }

    return CLI_SHUTDOWN;
}