本文整理汇总了C++中pthread_attr_setdetachstate函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_attr_setdetachstate函数的具体用法?C++ pthread_attr_setdetachstate怎么用?C++ pthread_attr_setdetachstate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_attr_setdetachstate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: analyze_masters
void analyze_masters(int argc, char *argv[],
import_options_t *analyzer,
forest_t *forest)
/* main entry point; collect and parse CVS masters */
{
char name[PATH_MAX];
const char *last = NULL;
char *file;
size_t i, j = 1;
int c;
#ifdef THREADS
pthread_attr_t attr;
/* Initialize and reinforce default thread non-detached attribute */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
#endif /* THREADS */
striplen = analyzer->striplen;
forest->textsize = forest->filecount = 0;
progress_begin("Reading file list...", NO_MAX);
for (;;)
{
struct stat stb;
int l;
if (argc < 2) {
/* coverity[tainted_data] Safe, never handed to exec */
if (fgets(name, sizeof(name), stdin) == NULL)
break;
l = strlen(name);
if (name[l-1] == '\n')
name[l-1] = '\0';
file = name;
} else {
file = argv[j++];
if (!file)
break;
}
if (stat(file, &stb) != 0)
continue;
else if (S_ISDIR(stb.st_mode) != 0)
continue;
else if (!analyzer->promiscuous)
{
char *end = file + strlen(file);
if (end - file < 2 || end[-1] != 'v' || end[-2] != ',')
continue;
if (strstr(file, "CVSROOT") != NULL)
continue;
}
forest->textsize += stb.st_size;
fn = xcalloc(1, sizeof(rev_filename), "filename gathering");
*fn_tail = fn;
fn_tail = (rev_filename **)&fn->next;
if (striplen > 0 && last != NULL) {
c = strcommonendingwith(file, last, '/');
if (c < striplen)
striplen = c;
} else if (striplen < 0) {
striplen = 0;
for (i = 0; i < strlen(file); i++)
if (file[i] == '/')
striplen = i + 1;
}
fn->file = atom(file);
last = fn->file;
total_files++;
if (progress && total_files % 100 == 0)
progress_jump(total_files);
}
forest->filecount = total_files;
generators = xcalloc(sizeof(generator_t), total_files, "Generators");
sorted_files = xmalloc(sizeof(rev_file) * total_files, "sorted_files");
cvs_masters = xcalloc(total_files, sizeof(cvs_master), "cvs_masters");
rev_masters = xmalloc(sizeof(rev_master) * total_files, "rev_masters");
fn_n = total_files;
i = 0;
rev_filename *tn;
for (fn = fn_head; fn; fn = tn) {
tn = fn->next;
sorted_files[i].name = fn->file;
sorted_files[i++].rectified = atom_rectify_name(fn->file);
free(fn);
}
#ifdef FILESORT
/*
* Sort list of files in path_deep_compare order of output name.
* cvs_masters and rev_masters will be mainteined in this order.
* This causes commits to come out in correct pack order.
* It also causes operations to come out in correct fileop_sort order.
* Note some output names are different to input names.
* e.g. .cvsignore becomes .gitignore
*/
qsort(sorted_files, total_files, sizeof(rev_file), file_compare);
#endif /*FILESORT */
//.........这里部分代码省略.........
开发者ID:USGS-CIDA,项目名称:migratingToGit,代码行数:101,代码来源:import.c
示例2: julia_init
//.........这里部分代码省略.........
}
// set module field of primitive types
int i;
void **table = jl_core_module->bindings.table;
for(i=1; i < jl_core_module->bindings.size; i+=2) {
if (table[i] != HT_NOTFOUND) {
jl_binding_t *b = (jl_binding_t*)table[i];
if (b->value && jl_is_datatype(b->value)) {
jl_datatype_t *tt = (jl_datatype_t*)b->value;
tt->name->module = jl_core_module;
}
}
}
// the Main module is the one which is always open, and set as the
// current module for bare (non-module-wrapped) toplevel expressions.
// it does "using Base" if Base is available.
if (jl_base_module != NULL) {
jl_add_standard_imports(jl_main_module);
}
// eval() uses Main by default, so Main.eval === Core.eval
jl_module_import(jl_main_module, jl_core_module, jl_symbol("eval"));
jl_current_module = jl_main_module;
#ifndef _OS_WINDOWS_
signal_stack = malloc(SIGSTKSZ);
struct sigaction actf;
memset(&actf, 0, sizeof(struct sigaction));
sigemptyset(&actf.sa_mask);
actf.sa_handler = fpe_handler;
actf.sa_flags = 0;
if (sigaction(SIGFPE, &actf, NULL) < 0) {
JL_PRINTF(JL_STDERR, "sigaction: %s\n", strerror(errno));
jl_exit(1);
}
#if defined(_OS_LINUX_)
stack_t ss;
ss.ss_flags = 0;
ss.ss_size = SIGSTKSZ;
ss.ss_sp = signal_stack;
if (sigaltstack(&ss, NULL) < 0) {
JL_PRINTF(JL_STDERR, "sigaltstack: %s\n", strerror(errno));
jl_exit(1);
}
struct sigaction act;
memset(&act, 0, sizeof(struct sigaction));
sigemptyset(&act.sa_mask);
act.sa_sigaction = segv_handler;
act.sa_flags = SA_ONSTACK | SA_SIGINFO;
if (sigaction(SIGSEGV, &act, NULL) < 0) {
JL_PRINTF(JL_STDERR, "sigaction: %s\n", strerror(errno));
jl_exit(1);
}
if (signal(SIGPIPE,SIG_IGN) == SIG_ERR) {
JL_PRINTF(JL_STDERR, "Couldn't set SIGPIPE\n");
jl_exit(1);
}
#elif defined (_OS_DARWIN_)
kern_return_t ret;
mach_port_t self = mach_task_self();
ret = mach_port_allocate(self,MACH_PORT_RIGHT_RECEIVE,&segv_port);
HANDLE_MACH_ERROR("mach_port_allocate",ret);
ret = mach_port_insert_right(self,segv_port,segv_port,MACH_MSG_TYPE_MAKE_SEND);
HANDLE_MACH_ERROR("mach_port_insert_right",ret);
// Alright, create a thread to serve as the listener for exceptions
pthread_t thread;
pthread_attr_t attr;
if (pthread_attr_init(&attr) != 0)
{
JL_PRINTF(JL_STDERR, "pthread_attr_init failed");
jl_exit(1);
}
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
if (pthread_create(&thread,&attr,mach_segv_listener,NULL) != 0)
{
JL_PRINTF(JL_STDERR, "pthread_create failed");
jl_exit(1);
}
pthread_attr_destroy(&attr);
ret = task_set_exception_ports(self,EXC_MASK_BAD_ACCESS,segv_port,EXCEPTION_DEFAULT,MACHINE_THREAD_STATE);
HANDLE_MACH_ERROR("task_set_exception_ports",ret);
#endif
#else
if (signal(SIGFPE, (void (__cdecl *)(int))fpe_handler) == SIG_ERR) {
JL_PRINTF(JL_STDERR, "Couldn't set SIGFPE\n");
jl_exit(1);
}
#endif
#ifdef JL_GC_MARKSWEEP
jl_gc_enable();
#endif
}
开发者ID:DylanGriffith,项目名称:julia,代码行数:101,代码来源:init.c
示例3: PNUM_get_port_number
void
RMTD_server_main
(
) {
int port_number, sig; /* parent port number */
/* Get a port number for the server */
port_number = PNUM_get_port_number ();
if (port_number == FAILURE) {
MISC_log ("Can not find a port number\n");
exit (1);
}
/* initialize client registration module */
if (CLRG_initialize (N_child) == FAILURE)
exit (1);
/* open the message server sockets */
if (MSGD_open_msg_server (port_number) == FAILURE)
exit (2);
/* open the RPC server socket */
if ((Rpc_pfd = SOCD_open_server (port_number)) == FAILURE) {
MISC_log ("Opening server failed\n");
exit (2);
}
MISC_log ("Max number of children set to %d", N_child);
MISC_log ("The port number is %d", port_number);
/* go to background */
if (Run_in_background)
Goto_background ();
RMT_access_disc_file (1, " \n", 3);
/* Catch SIGCLD for calling wait to remove dead child */
if (Set_signal_action (SIGCLD, Sigcld_int) == FAILURE)
exit (1);
for (sig = 1; sig <= 32; sig++) { /* catch other signals */
if (sig == SIGCLD || sig == SIGKILL || sig == SIGSTOP)
continue;
if (sig == SIGPIPE)
Set_signal_action (sig, SIG_IGN);
else
Set_signal_action (sig, Termination_exit);
}
/* write the PID to the file */
MISC_log ("PID: %d", (int) getpid());
MISC_log ("%s starts operation\n", Prog_name);
while (1) { /* The main loop. It never ends. */
int sfd[2]; /* socket fd pairs created by the stream pipe */
if (Iamchild == RMT_TRUE) { /* The child */
#ifdef THREADED
int rtn;
if ((rtn = pthread_attr_init (&pthread_custom_attr)) != 0) {
MISC_log ("pthread_attr_init failed %d:%s\n",
rtn, strerror (rtn));
exit(0);
}
if (( rtn = pthread_attr_setdetachstate (&pthread_custom_attr,
PTHREAD_CREATE_DETACHED)) != 0) {
MISC_log ("pthread_attr_setdetachstate failed %d:%s\n",
rtn,strerror(rtn));
exit(0);
}
#else
void *buf;
Manage_clients (MC_INIT, 0, &buf);
#endif
while (1) {
int fd; /* client fd */
#ifdef THREADED
{ /* waiting for a new fd from the parent */
fd_set readfds;
FD_ZERO (&readfds);
FD_SET (sfd[0], &readfds);
select (FD_SETSIZE, &readfds, NULL, NULL, NULL);
}
if ((fd = Receive_pipe_msg_from_parent (sfd[0])) < 0)
continue;
pthread_mutex_lock (&countMutex);
Num_threads++;
pthread_mutex_unlock (&countMutex);
pthread_create (&newThread, &pthread_custom_attr,
Process_child, (void *)fd);
#else
fd = Manage_clients (MC_POLL, sfd[0], &buf);
if (fd >= 0) {
int ret = Process_child (fd);
if (ret < 0)
Manage_clients (MC_DELETE, fd, &buf);
}
//.........这里部分代码省略.........
开发者ID:likev,项目名称:CodeOrpgPub,代码行数:101,代码来源:rmt_server.c
示例4: main
int main( int argc, char **argv )
{
/* -------------------------------------------------------------------- */
/* Our first pass is to establish the correct answers for all */
/* the tests. */
/* -------------------------------------------------------------------- */
int i, test_count = sizeof(test_list) / sizeof(TestItem);
for( i = 0; i < test_count; i++ )
{
TestItem *test = test_list + i;
projPJ src_pj, dst_pj;
src_pj = pj_init_plus( test->src_def );
dst_pj = pj_init_plus( test->dst_def );
if( src_pj == NULL )
{
printf( "Unable to translate:\n%s\n", test->src_def );
test->skip = 1;
continue;
}
if( dst_pj == NULL )
{
printf( "Unable to translate:\n%s\n", test->dst_def );
test->skip = 1;
continue;
}
test->dst_x = test->src_x;
test->dst_y = test->src_y;
test->dst_z = test->src_z;
test->dst_error = pj_transform( src_pj, dst_pj, 1, 0,
&(test->dst_x),
&(test->dst_y),
&(test->dst_z) );
pj_free( src_pj );
pj_free( dst_pj );
test->skip = 0;
#ifdef notdef
printf( "Test %d - output %.14g,%.14g,%g\n", i, test->dst_x, test->dst_y, test->dst_z );
#endif
}
printf( "%d tests initialized.\n", test_count );
/* -------------------------------------------------------------------- */
/* Now launch a bunch of threads to repeat the tests. */
/* -------------------------------------------------------------------- */
#ifdef _WIN32
{ //Scoped to workaround lack of c99 support in VS
HANDLE ahThread[num_threads];
for( i = 0; i < num_threads; i++ )
{
active_thread_count++;
ahThread[i] = CreateThread(NULL, 0, WinTestThread, NULL, 0, NULL);
if (ahThread[i] == 0)
{
printf( "Thread creation failed.");
return 1;
}
}
printf( "%d test threads launched.\n", num_threads );
WaitForMultipleObjects(num_threads, ahThread, TRUE, INFINITE);
}
#else
{
pthread_t ahThread[num_threads];
pthread_attr_t hThreadAttr;
pthread_attr_init( &hThreadAttr );
pthread_attr_setdetachstate( &hThreadAttr, PTHREAD_CREATE_DETACHED );
for( i = 0; i < num_threads; i++ )
{
active_thread_count++;
pthread_create( &(ahThread[i]), &hThreadAttr,
PosixTestThread, NULL );
}
printf( "%d test threads launched.\n", num_threads );
while( active_thread_count > 0 )
sleep( 1 );
}
//.........这里部分代码省略.........
开发者ID:Fooway,项目名称:proj.4,代码行数:101,代码来源:multistresstest.c
示例5: slurm_mutex_lock
/* Process incoming RPCs. Meant to execute as a pthread */
extern void *rpc_mgr(void *no_data)
{
pthread_attr_t thread_attr_rpc_req;
slurm_fd_t sockfd, newsockfd;
int i, retry_cnt, sigarray[] = {SIGUSR1, 0};
slurm_addr_t cli_addr;
slurmdbd_conn_t *conn_arg = NULL;
slurm_mutex_lock(&thread_count_lock);
master_thread_id = pthread_self();
slurm_mutex_unlock(&thread_count_lock);
(void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
(void) pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
/* threads to process individual RPC's are detached */
slurm_attr_init(&thread_attr_rpc_req);
if (pthread_attr_setdetachstate
(&thread_attr_rpc_req, PTHREAD_CREATE_DETACHED))
fatal("pthread_attr_setdetachstate %m");
/* initialize port for RPCs */
if ((sockfd = slurm_init_msg_engine_port(get_dbd_port()))
== SLURM_SOCKET_ERROR)
fatal("slurm_init_msg_engine_port error %m");
/* Prepare to catch SIGUSR1 to interrupt accept().
* This signal is generated by the slurmdbd signal
* handler thread upon receipt of SIGABRT, SIGINT,
* or SIGTERM. That thread does all processing of
* all signals. */
xsignal(SIGUSR1, _sig_handler);
xsignal_unblock(sigarray);
/*
* Process incoming RPCs until told to shutdown
*/
while ((i = _wait_for_server_thread()) >= 0) {
/*
* accept needed for stream implementation is a no-op in
* message implementation that just passes sockfd to newsockfd
*/
if ((newsockfd = slurm_accept_msg_conn(sockfd,
&cli_addr)) ==
SLURM_SOCKET_ERROR) {
_free_server_thread((pthread_t) 0);
if (errno != EINTR)
error("slurm_accept_msg_conn: %m");
continue;
}
fd_set_nonblocking(newsockfd);
conn_arg = xmalloc(sizeof(slurmdbd_conn_t));
conn_arg->newsockfd = newsockfd;
slurm_get_ip_str(&cli_addr, &conn_arg->orig_port,
conn_arg->ip, sizeof(conn_arg->ip));
retry_cnt = 0;
while (pthread_create(&slave_thread_id[i],
&thread_attr_rpc_req,
_service_connection,
(void *) conn_arg)) {
if (retry_cnt > 0) {
error("pthread_create failure, "
"aborting RPC: %m");
close(newsockfd);
break;
}
error("pthread_create failure: %m");
retry_cnt++;
usleep(1000); /* retry in 1 msec */
}
}
debug3("rpc_mgr shutting down");
slurm_attr_destroy(&thread_attr_rpc_req);
(void) slurm_shutdown_msg_engine(sockfd);
_wait_for_thread_fini();
pthread_exit((void *) 0);
return NULL;
}
开发者ID:HDOD,项目名称:slurm,代码行数:81,代码来源:rpc_mgr.c
示例6: main
int main (int argc, char *argv[])
{
int i;
double *a, *b;
int status;
pthread_attr_t attr;
int ret_count;
printf("\n\t\t---------------------------------------------------------------------------");
printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
printf("\n\t\t Email : RarchK");
printf("\n\t\t---------------------------------------------------------------------------");
printf("\n\t\t Objective : To perform dot product of vector using Mutex.\n ");
printf("\n\t\t..........................................................................\n");
/* Assign storage and initialize values */
a = (double*) malloc (NUMTHRDS*VECLEN*sizeof(double));
b = (double*) malloc (NUMTHRDS*VECLEN*sizeof(double));
for (i=0; i<VECLEN*NUMTHRDS; i++)
{
a[i]=1.0;
b[i]=a[i];
}
dotstr.veclen = VECLEN;
dotstr.a = a;
dotstr.b = b;
dotstr.sum=0;
ret_count=pthread_mutex_init(&mutexsum, NULL);
if (ret_count)
{
printf("ERROR; return code from pthread_mutex_init() is %d\n", ret_count);
exit(-1);
}
/* Create threads to perform the dotproduct */
ret_count=pthread_attr_init(&attr);
if (ret_count)
{
printf("ERROR; return code from pthread_attr_init() is %d\n", ret_count);
exit(-1);
}
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for(i=0; i<NUMTHRDS; i++)
{
/*
Each thread works on a different set of data.
The offset is specified by 'i'. The size of
the data for each thread is indicated by VECLEN.
*/
ret_count=pthread_create( &callThd[i], &attr, dotprod, (void *)i);
if (ret_count)
{
printf("ERROR; return code from pthread_create() is %d\n", ret_count);
exit(-1);
}
}
ret_count=pthread_attr_destroy(&attr);
if(ret_count)
{
printf("\n ERROR : return code from pthread_attr_destroy() is %d\n",ret_count);
exit(-1);
}
/* Wait on the other threads */
/*for(i=0; i<NUMTHRDS; i++)
{
ret_count=pthread_join( callThd[i], (void **)&status);
if (ret_count)
{
printf("ERROR; return code from pthread_join() is %d\n", ret_count);
exit(-1);
}
}*/
for(i=0; i<NUMTHRDS; i++)
pthread_join( callThd[i], (void **)&status);
/* After joining, print out the results and cleanup */
printf ("Sum = %f \n", dotstr.sum);
free (a);
free (b);
ret_count=pthread_mutex_destroy(&mutexsum);
if (ret_count)
{
printf("ERROR; return code from pthread_mutex_destroy() is %d\n", ret_count);
exit(-1);
}
//.........这里部分代码省略.........
开发者ID:41i,项目名称:ZeroSample,代码行数:101,代码来源:pthread-mutex.c
示例7: start_rdma_threads
int start_rdma_threads(struct sock_t *sock, struct rdma_resource_t *rdma_resource,
struct sock_bind_t *sock_bind)
{
int i, j;
int rc;
int ret = 0;
unsigned long exit_code;
struct thread_context_t *t_ctx;
struct user_param_t *user_param = &(rdma_resource->user_param);
pthread_attr_t attr;
pthread_attr_init(&attr);
if (user_param->server_ip) {
rdma_resource->client_ctx =
(struct thread_context_t*)malloc(sizeof(struct thread_context_t) * user_param->num_of_thread);
} else {
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
}
i = 0;
while (1) {
if (user_param->server_ip) {
t_ctx = &rdma_resource->client_ctx[i];
} else {
t_ctx = (struct thread_context_t*)malloc(sizeof(struct thread_context_t));
}
t_ctx->rdma_resource = rdma_resource;
rc = sock_connect_multi(sock_bind, &(t_ctx->sock));
if (rc) {
ERROR("Failed to open connection between the 2 sides.\n");
goto failure_1;
}
rc = pthread_create(&(t_ctx->thread), &attr, rdma_thread, t_ctx);
if (rc != 0) {
ERROR("Failed to create thread.\n");
break;
}
i++;
if (i >= user_param->num_of_thread && (user_param->server_ip)) {
break;
}
}
if (user_param->server_ip) {
if (i != user_param->num_of_thread) {
for (j = 0; j < i; j++) {
t_ctx = &rdma_resource->client_ctx[i];
pthread_cancel(t_ctx->thread);
pthread_join(t_ctx->thread, (void *)&exit_code);
}
ret = 1;
}
for (i = 0; i < user_param->num_of_thread; i++) {
t_ctx = &rdma_resource->client_ctx[i];
rc = pthread_join(t_ctx->thread, (void *)&exit_code);
if ((rc != 0) || (exit_code != 0)) {
ERROR("Failed to wait for thread[%d] termination.\n", i);
ret = 1;
} else {
INFO("Thread[%d] finished with return value %lu\n", i, exit_code);
if (t_ctx->min_lat < rdma_resource->min_lat) {
rdma_resource->min_lat = t_ctx->min_lat;
rdma_resource->min_lat_iter_num = t_ctx->min_lat_iter_num;
}
if (t_ctx->max_lat > rdma_resource->max_lat) {
rdma_resource->max_lat = t_ctx->max_lat;
rdma_resource->max_lat_iter_num = t_ctx->max_lat_iter_num;
}
for (j = 0; j < LAT_LEVEL; j++) {
rdma_resource->lat[j] += t_ctx->lat[j];
}
}
sock_close_multi(&(t_ctx->sock), sock_bind);
}
free(rdma_resource->client_ctx);
INFO("Got min lat %f when sending NO.%u packet.\n", rdma_resource->min_lat, rdma_resource->min_lat_iter_num);
INFO("Got max lat %f when sending NO.%u packet.\n", rdma_resource->max_lat, rdma_resource->max_lat_iter_num);
for (i = 0; i < LAT_LEVEL; i++) {
if (i < 7) {
INFO("The number of Lat < %4dus is %3d \n", (1 + i), rdma_resource->lat[i]);
} else {
INFO("The number of Lat < %4dus is %3d \n", (1 << (i - 4)), rdma_resource->lat[i]);
}
}
}
failure_1:
return ret;
//.........这里部分代码省略.........
开发者ID:li-ch,项目名称:rdma-examples,代码行数:101,代码来源:rdma_thread.c
示例8: server
//.........这里部分代码省略.........
for(int i = 0; i < Dlugosc - k; i++) {
l = i;
for(int j = 0; j < k; j++) {
if(Rezerwacje[i+j] > 0) {
l = -1;
i = i + j;
break;
}
}
if(l + k == Dlugosc) {
combine(response, response_length, "%c", ACT_REJECT);
pthread_mutex_unlock(&ochrona);
return 0;
}
if(l != -1) {
int sumcost = 0;
int ndw = 0;
for(int ii = 0; ii < Dlugosc; ii++) {
if(Wydobyte[l+ii] < Glebokosc) {
ndw = 1;
break;
}
}
if(ndw == 0) {
continue;
}
for(int i = 0; i < Glebokosc; i++) {
int line_cost = 0;
for(int j = 0; j < k; j++) {
if(Wydobyte[j+l] > i) continue;
line_cost += Szacunek[(j+l)*Glebokosc+i];
if(line_cost > z) {
line_cost = z + 1;
break;
}
}
if(line_cost == z + 1) break;
else if(line_cost + sumcost > z) break;
sumcost += line_cost;
g = i + 1;
}
if(g == 0 || sumcost > z) {
continue;
}
}
}
int ret2 = change_money_of_company(bQ, idx, id, -z, museum_ip);
if(ret2 == 1) {
combine(response, response_length, "%c", ACT_REJECT);
pthread_mutex_unlock(&ochrona);
return 0;
} else if(ret2 == -1) {
combine(response, response_length, "%c", ACT_ERROR);
pthread_mutex_unlock(&ochrona);
return 0;
}
for(int i = 0; i < k; i++) {
Rezerwacje[i+l] = g;
Uswiadomione[i+l] = 0;
}
pthread_mutex_unlock(&ochrona);
// OK - create delegate
Delegaci[idx].zajety = 1;
Delegaci[idx].ip = delegate_base_ip + idx;
Delegaci[idx].l = l;
Delegaci[idx].g = g;
Delegaci[idx].do_exit = 0;
Delegaci[idx].k = k;
pthread_attr_t attrs;
pthread_attr_init(&attrs);
pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
int ret3 = pthread_create(&(Delegaci[idx].thread), &attrs, delegate, Delegaci+idx);
if(ret3 != 0) {
error("Failed with creating thread.");
pthread_attr_destroy(&attrs);
return -1;
}
pthread_attr_destroy(&attrs);
combine(response, response_length, "%c %i %i %l", ACT_OK, l, g, delegate_base_ip + idx);
return 0;
} else {
combine(response, response_length, "%c", ACT_ERROR);
return 0;
}
} else if(cmd == ACT_MUSEUM_REPORT_INIT || cmd == ACT_MUSEUM_SEND_REPORT_PART
|| cmd == ACT_MUSEUM_COMPANY_EXIT) {
if(report_server(query, query_length, response, response_length, source, arg) == 0)
return 0;
else
return -1;
} else {
warning("Unsupported command 0x%x.", cmd);
combine(response, response_length, "%c", ACT_ERROR);
return 0;
}
assert(0);
return -1;
}
开发者ID:wojtex,项目名称:studia-so-archeo,代码行数:101,代码来源:museum.c
示例9: main
int
main (int argc, char *argv[])
{
pthread_t threads[THREAD_COUNT];
pthread_attr_t detach;
int status;
void *result;
int i;
status = pthread_attr_init (&detach);
if (status != 0)
err_abort (status, "Init attributes object");
status = pthread_attr_setdetachstate (
&detach, PTHREAD_CREATE_DETACHED);
if (status != 0)
err_abort (status, "Set create-detached");
for (i = 0; i< THREAD_COUNT; i++) {
status = pthread_create (
&threads[i], &detach, thread_routine, (void *)i);
if (status != 0)
err_abort (status, "Create thread");
}
sleep (1);
for (i = 0; i < THREAD_COUNT/2; i++) {
printf ("Suspending thread %d.\n", i);
status = thd_suspend (threads[i]);
if (status != 0)
err_abort (status, "Suspend thread");
}
printf ("Sleeping ...\n");
sleep (1);
for (i = 0; i < THREAD_COUNT/2; i++) {
printf ("Continuing thread %d.\n", i);
status = thd_continue (threads[i]);
if (status != 0)
err_abort (status, "Suspend thread");
}
for (i = THREAD_COUNT/2; i < THREAD_COUNT; i++) {
printf ("Suspending thread %d.\n", i);
status = thd_suspend (threads[i]);
if (status != 0)
err_abort (status, "Suspend thread");
}
printf ("Sleeping ...\n");
sleep (1);
for (i = THREAD_COUNT/2; i < THREAD_COUNT; i++) {
printf ("Continuing thread %d.\n", i);
status = thd_continue (threads[i]);
if (status != 0)
err_abort (status, "Continue thread");
}
/*
* Request that each thread terminate. We don't bother waiting for them;
* just trust that they will terminate in "reasonable time". When the last
* thread exits, the process will exit.
*/
for (i = 0; i < THREAD_COUNT; i++)
pthread_cancel (threads[i]);
pthread_exit (NULL); /* Let threads finish */
}
开发者ID:keyz182,项目名称:BOINC-7.0,代码行数:70,代码来源:susp.cpp
示例10: message
//.........这里部分代码省略.........
// save the socket ID for the next calls
fp->rmt_sockctrl= sockctrl; // Needed to send an error on the ctrl connection
// Now I can set the filter
if ( daemon_unpackapplyfilter(fp, &nread, &plen, errbuf) )
goto error;
// Now, I can send a RPCAP start capture reply message
if ( sock_bufferize(NULL, sizeof(struct rpcap_header), NULL, &sendbufidx,
RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, errbuf, PCAP_ERRBUF_SIZE) == -1)
goto error;
rpcap_createhdr( (struct rpcap_header *) sendbuf, RPCAP_MSG_STARTCAP_REPLY, 0, sizeof(struct rpcap_startcapreply) );
startcapreply= (struct rpcap_startcapreply *) &sendbuf[sendbufidx];
if ( sock_bufferize(NULL, sizeof(struct rpcap_startcapreply), NULL,
&sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, errbuf, PCAP_ERRBUF_SIZE) == -1)
goto error;
memset(startcapreply, 0, sizeof(struct rpcap_startcapreply) );
startcapreply->bufsize= htonl(fp->bufsize);
if (!serveropen_dp)
{
unsigned short port = (unsigned short)strtoul(portdata,NULL,10);
startcapreply->portdata= htons(port);
}
if ( sock_send(sockctrl, sendbuf, sendbufidx, errbuf, PCAP_ERRBUF_SIZE) == -1)
goto error;
if (!serveropen_dp)
{
SOCKET socktemp; // We need another socket, since we're going to accept() a connection
// Connection creation
saddrlen = sizeof(struct sockaddr_storage);
socktemp= accept(sockdata, (struct sockaddr *) &saddr, &saddrlen);
if (socktemp == -1)
{
sock_geterror("accept(): ", errbuf, PCAP_ERRBUF_SIZE);
goto error;
}
// Now that I accepted the connection, the server socket is no longer needed
sock_close(sockdata, errbuf, PCAP_ERRBUF_SIZE);
sockdata= socktemp;
}
fp->rmt_sockdata= sockdata;
/* GV we need this to create the thread as detached. */
/* GV otherwise, the thread handle is not destroyed */
pthread_attr_init(&detachedAttribute);
pthread_attr_setdetachstate(&detachedAttribute, PTHREAD_CREATE_DETACHED);
// Now we have to create a new thread to receive packets
if ( pthread_create(threaddata, &detachedAttribute, (void *) daemon_thrdatamain, (void *) fp) )
{
snprintf(errbuf, PCAP_ERRBUF_SIZE, "Error creating the data thread");
pthread_attr_destroy(&detachedAttribute);
goto error;
}
pthread_attr_destroy(&detachedAttribute);
// Check if all the data has been read; if not, discard the data in excess
if (nread != plen)
sock_discard(sockctrl, plen - nread, NULL, 0);
return fp;
error:
rpcap_senderror(sockctrl, errbuf, PCAP_ERR_STARTCAPTURE, NULL);
if (addrinfo)
freeaddrinfo(addrinfo);
if (threaddata)
pthread_cancel(*threaddata);
if (sockdata)
sock_close(sockdata, NULL, 0);
// Check if all the data has been read; if not, discard the data in excess
if (nread != plen)
sock_discard(sockctrl, plen - nread, NULL, 0);
if (fp)
{
pcap_close(fp);
fp= NULL;
}
return NULL;
}
开发者ID:Jumbo88888,项目名称:rpcapd-linux,代码行数:101,代码来源:daemon.c
示例11: create_subprocess
static int create_subprocess(const char *cmd, const char *arg0, const char *arg1, char **envp,
int* pProcessId)
{
char *devname;
int ptm;
pid_t pid;
char tmpdir[PATH_MAX];
char terminfodir[PATH_MAX];
sprintf((char*)default_vimruntime_dir, "%s/vim/", cmd);
sprintf((char*)default_vim_dir, "%s/vim/", cmd);
sprintf(tmpdir, "%s/tmp", cmd);
sprintf(terminfodir, "%s/terminfo", cmd);
pipe(fake_gpm_fd);
ptm = open("/dev/ptmx", O_RDWR); // | O_NOCTTY);
if(ptm < 0){
LOGE("[ cannot open /dev/ptmx - %s ]\n",strerror(errno));
return -1;
}
fcntl(ptm, F_SETFD, FD_CLOEXEC);
if(grantpt(ptm) || unlockpt(ptm) ||
((devname = (char*) ptsname(ptm)) == 0)){
LOGE("[ trouble with /dev/ptmx - %s ]\n", strerror(errno));
return -1;
}
setenv("TMPDIR", tmpdir, 1);
setenv("TERM", "linux", 1);
//setenv("HOME", cmd, 1);
setenv("TERMINFO", terminfodir, 1);
if (envp) {
for (; *envp; ++envp) {
putenv(*envp);
}
}
char** thread_arg = (char**)malloc(sizeof(char*)*2);
thread_arg[0] = strdup(devname);
if(arg0)
thread_arg[1] = strdup(arg0);
else
thread_arg[1] = NULL;
pthread_t thread_id;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_mutex_init(&global_mutex, NULL);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_create(&thread_id, &attr, thread_wrapper, (void*)thread_arg);
pthread_attr_destroy(&attr);
*pProcessId = (int) thread_id;
thread_data.insert(std::make_pair(thread_id, thread_arg));
return ptm;
/*
pid = fork();
if(pid < 0) {
LOGE("- fork failed: %s -\n", strerror(errno));
return -1;
}
if(pid == 0){
close(ptm);
int pts;
setsid();
pts = open(devname, O_RDWR);
if(pts < 0) exit(-1);
dup2(pts, 0);
dup2(pts, 1);
dup2(pts, 2);
char* argv[3];
argv[0] = (char*)"vim";
argv[1] = (char*)arg0;
argv[2] = NULL;
AndroidMain(2, (char**)argv);
exit(-1);
} else {
*pProcessId = (int) pid;
return ptm;
}
*/
}
开发者ID:Smileyt,项目名称:vimtouch,代码行数:95,代码来源:termExec.cpp
示例12: initialiseMDSM
//.........这里部分代码省略.........
survey -> nchans * sizeof(float));
// Log parameters
printf("Observation Params: ndms = %d, maxDM = %f\n", survey -> tdms,
survey -> lowdm + survey -> dmstep * (survey -> tdms - 1));
printf("Observation Params: nchans = %d, nsamp = %d, tsamp = %f\n",
survey -> nchans, survey -> nsamp, survey -> tsamp);
printf("Beam Params:\n");
for(i = 0; i < survey -> nbeams; i++)
{
BEAM beam = survey -> beams[i];
printf(" Beam %d: fch1 = %f, foff = %f, maxshift = %d, gpuID = %d\n",
beam.beam_id, beam.fch1, beam.foff, beam.maxshift, beam.gpu_id);
}
printf("\n");
if (survey -> apply_beamforming) printf("- Performing beamforming\n");
if (survey -> apply_rfi_clipper ) printf("- Clipping RFI\n");
printf("- Performing dedispersion\n");
if (survey -> apply_detrending ) printf("- Performing detrending\n");
if (survey -> apply_median_filter ) printf("- Performing median filtering\n");
if (survey -> dump_to_disk) printf("- Dump to disk mode enabled\n");
if (survey -> apply_clustering) printf("- Applying DBSCAN\n");
if (survey -> tbb_enabled) printf("- TBB mode enabled\n");
printf("\n");
printf("============================================================================\n");
// Initialise processing threads
pthread_attr_init(&thread_attr);
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
survey -> num_threads = survey -> nbeams;
threads = (pthread_t *) calloc(sizeof(pthread_t), survey -> num_threads);
threads_params = (THREAD_PARAMS **) safeMalloc(survey -> num_threads * sizeof(THREAD_PARAMS*));
for(i = 0; i < survey -> num_threads; i++)
threads_params[i] = (THREAD_PARAMS *) safeMalloc(sizeof(THREAD_PARAMS));
// Initialise barriers
if (pthread_barrier_init(&input_barrier, NULL, survey -> num_threads + 2))
{ fprintf(stderr, "Unable to initialise input barrier\n"); exit(0); }
if (pthread_barrier_init(&output_barrier, NULL, survey -> num_threads + 2))
{ fprintf(stderr, "Unable to initialise output barrier\n"); exit(0); }
// Create GPU objects and allocate beams/threads to them
GPU **gpus = (GPU **) malloc(survey -> num_gpus * sizeof(GPU *));
for(i = 0; i < survey -> num_gpus; i++)
{
gpus[i] = (GPU *) malloc(sizeof(GPU));
gpus[i] -> device_id = survey -> gpu_ids[i];
gpus[i] -> num_threads = 0;
gpus[i] -> primary_thread = 0;
gpus[i] -> thread_ids = (unsigned *) malloc(8 * sizeof(unsigned));
}
// Allocate GPUs to beams (split beams among GPUs, one beam cannot be processed on more than 1 GPU)
for(i = 0; i < survey -> num_threads; i++)
{
unsigned gpu = (survey -> gpu_ids)[i % survey -> num_gpus];
// Update GPU properties
for(j = 0; j < survey -> num_gpus; j++)
开发者ID:jintaoluo,项目名称:MDSM,代码行数:67,代码来源:multibeam_dedispersion_manager.cpp
示例13: handler
/*!
\brief 'true' main of the program.
It must be in a separate function because:
- if we're in 'console' mode, we have to put the main thread waiting for a Ctrl+C
(in order to be able to stop everything)
- if we're in daemon mode, the main program must terminate and a new child must be
created in order to create the daemon
\param ptr: it keeps the main socket handler (what's called 'sockmain' in the main()), that
represents the socket used in the main connection. It is a 'void *' just because pthreads
want this format.
*/
static void main_passive(void *ptr)
{
char errbuf[PCAP_ERRBUF_SIZE + 1]; // keeps the error string, prior to be printed
SOCKET sockctrl; // keeps the socket ID for this control connection
struct sockaddr_storage from; // generic sockaddr_storage variable
socklen_t fromlen; // keeps the length of the sockaddr_storage variable
SOCKET sockmain;
#ifndef USE_THREADS
pid_t pid;
#endif
sockmain = *((SOCKET *) ptr);
// Delete the pointer (which has been allocated in the main)
free(ptr);
// Initialize errbuf
memset(errbuf, 0, sizeof(errbuf));
// main thread loop
while (1)
{
#ifdef USE_THREADS
pthread_t threadId; // Pthread variable that keeps the thread structures
pthread_attr_t detachedAttribute;
#endif
struct daemon_slpars *pars; // parameters needed by the daemon_serviceloop()
// Connection creation
fromlen = sizeof(struct sockaddr_storage);
sockctrl = accept(sockmain, (struct sockaddr *) &from, &fromlen);
if (sockctrl == -1)
{
// The accept() call can return this error when a signal is catched
// In this case, we have simply to ignore this error code
// Stevens, pg 124
#ifdef _WIN32
if (WSAGetLastError() == WSAEINTR)
#else
if (errno == EINTR)
#endif
continue;
// Don't check for errors here, since the error can be due to the fact that the thread
// has been killed
sock_geterror("accept(): ", errbuf, PCAP_ERRBUF_SIZE);
SOCK_ASSERT(errbuf, 1);
continue;
}
// checks if the connecting host is among the ones allowed
if (sock_check_hostlist(hostlist, RPCAP_HOSTLIST_SEP, &from, errbuf, PCAP_ERRBUF_SIZE) < 0)
{
rpcap_senderror(sockctrl, errbuf, PCAP_ERR_HOSTNOAUTH, NULL);
sock_close(sockctrl, NULL, 0);
continue;
}
#ifdef USE_THREADS
// in case of passive mode, this variable is deallocated by the daemon_serviceloop()
pars = (struct daemon_slpars *) malloc (sizeof(struct daemon_slpars));
if (pars == NULL)
{
snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc() failed: %s", pcap_strerror(errno));
continue;
}
pars->sockctrl = sockctrl;
pars->activeclose = 0; // useless in passive mode
pars->isactive = 0;
pars->nullAuthAllowed = nullAuthAllowed;
/* GV we need this to create the thread as detached. */
/* GV otherwise, the thread handle is not destroyed */
pthread_attr_init(&detachedAttribute);
pthread_attr_setdetachstate(&detachedAttribute, PTHREAD_CREATE_DETACHED);
if (pthread_create(&threadId, &detachedAttribute, (void *) &daemon_serviceloop, (void *) pars))
{
SOCK_ASSERT("Error creating the child thread", 1);
pthread_attr_destroy(&detachedAttribute);
continue;
}
pthread_attr_destroy(&detachedAttribute);
//.........这里部分代码省略.........
开发者ID:EIChaoYang,项目名称:libpcap,代码行数:101,代码来源:rpcapd.c
示例14: main_startup
void main_startup(void)
{
char errbuf[PCAP_ERRBUF_SIZE + 1]; // keeps the error string, prior to be printed
struct addrinfo *addrinfo; // keeps the addrinfo chain; required to open a new socket
int i;
#ifdef USE_THREADS
pthread_t threadId; // Pthread variable that keeps the thread structures
pthread_attr_t detachedAttribute; // PThread attribute needed to create the thread as detached
#else
pid_t pid;
#endif
i = 0;
addrinfo = NULL;
memset(errbuf, 0, sizeof(errbuf));
// Starts all the active threads
while ((activelist[i].address[0] != 0) && (i < MAX_ACTIVE_LIST))
{
activelist[i].ai_family = mainhints.ai_family;
#ifdef USE_THREADS
/* GV we need this to create the thread as detached. */
/* GV otherwise, the thread handle is not destroyed */
pthread_attr_init(&detachedAttribute);
pthread_attr_setdetachstate(&detachedAttribute, PTHREAD_CREATE_DETACHED);
if (pthread_create(&threadId, &detachedAttribute, (void *) &main_active, (void *) &activelist[i]))
{
SOCK_ASSERT("Error creating the active child thread", 1);
pthread_attr_destroy(&detachedAttribute);
continue;
}
pthread_attr_destroy(&detachedAttribute);
#else
if ((pid = fork()) == 0) // I am the child
{
main_active((void *) &activelist[i]);
exit(0);
}
#endif
i++;
}
/*
* The code that manages the active connections is not blocking;
* the code that manages the passive connection is blocking.
* So, if the user does not want to run in passive mode, we have
* to block the main thread here, otherwise the program ends and
* all threads are stopped.
*
* WARNING: this means that in case we have only active mode,
* the program does not terminate even if all the child thread
* terminates. The user has always to press Ctrl+C (or send a
* SIGTERM) to terminate the program.
*/
if (passivemode)
{
struct addrinfo *tempaddrinfo;
// Do the work
if (sock_initaddress((address[0]) ? address : NULL, port, &mainhints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1)
{
SOCK_ASSERT(errbuf, 1);
return;
}
tempaddrinfo = addrinfo;
while (tempaddrinfo)
{
SOCKET *socktemp;
if ((sockmain = sock_open(tempaddrinfo, SOCKOPEN_SERVER, SOCKET_MAXCONN, errbuf, PCAP_ERRBUF_SIZE)) == -1)
{
SOCK_ASSERT(errbuf, 1);
tempaddrinfo = tempaddrinfo->ai_next;
continue;
}
// This trick is needed in order to allow the child thread to save the 'sockmain' variable
// withouth getting it overwritten by the sock_open, in case we want to open more than one waiting sockets
// For instance, the pthread_create() will accept the socktemp variable, and it will deallocate immediately that variable
socktemp = (SOCKET *) malloc (sizeof (SOCKET));
if (socktemp == NULL)
exit(0);
*socktemp = sockmain;
#ifdef USE_THREADS
/* GV we need this to create the thread as detached. */
/* GV otherwise, the thread handle is not destroyed */
pthread_attr_init(&detachedAttribute);
pthread_attr_setdetachstate(&detachedAttribute, PTHREAD_CREATE_DETACHED);
if (pthread_create(&threadId, &detachedAttribute, (void *) &main_passive, (void *) socktemp))
{
SOCK_ASSERT("Error creating the passive child thread", 1);
pthread_attr_destroy(&detachedAttribute);
continue;
//.........这里部分代码省略.........
开发者ID:EIChaoYang,项目名称:libpcap,代码行数:101,代码来源:rpcapd.c
示例15: main
//Main program
int main(void) {
int receivedBytes;//, sentBytes;
//unsigned char outBuff[BUFFER_MAX];
unsigned char inBuff[BUFFER_MAX];
//Reserve memory
char* cmd = malloc((BUFFER_MAX+1) * sizeof(char));
char* par = malloc((BUFFER_MAX+1) * sizeof(char));
struct commandStructure command;
//Threads variables
pthread_t logThread;
pthread_t emailThread;
//pthread_t debugThread;
pthread_t webcamThread;
pthread_t emailPhotoThread;
//Empty buffers
init();
// Open serial file descriptor
int fd = openSerial();
//Loop to scan
while(1){
receivedBytes = read(fd,inBuff,BUFFER_MAX);
if(receivedBytes > 0){ // Data found!
if(DEBUG){
printf("\nPayload size: %d\n",receivedBytes);
int i;
for(i=0;i<receivedBytes;i++){
printf("%c",inBuff[i]);
}
printf("\n");
}
getCmd(inBuff,cmd);
getPar(inBuff,par);
int pars = parseParameters(par);
if(!validCommand(cmd)){
printf("Invalid Command: %s\n\n",cmd);
continue;
}else{
//printf("Command: %s\n",cmd);
//int i = 0;
//printf("Parameters found: %d\n",pars);
//for(i=0;i<pars;i++) printf("Parameter %d - %s\n",i,PARAMETERS[i]);
}
if(compareText(cmd,"Debug")){ //thread is detached so resources can be recycled.
command.cmd = cmd;
command.pa
|
请发表评论