本文整理汇总了C++中pthread_barrier_wait函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_barrier_wait函数的具体用法?C++ pthread_barrier_wait怎么用?C++ pthread_barrier_wait使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_barrier_wait函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: load_ppp_module
static
uintptr_t
load_ppp_module()
{
if (module_dl_handler) {
// already loaded
return 0;
}
// allocate auxiliary instance
if (!aux_instance) {
aux_instance = calloc(1, sizeof(*aux_instance));
if (!aux_instance)
return 1;
aux_instance->id = tables_generate_new_pp_instance_id();
tables_add_pp_instance(aux_instance->id, aux_instance);
}
// allocate message loop for browser thread
if (ppb_message_loop_get_current() == 0) {
PP_Resource message_loop = ppb_message_loop_create(aux_instance->id);
ppb_message_loop_attach_to_current_thread(message_loop);
ppb_message_loop_proclaim_this_thread_browser();
}
// allocate message loop for plugin thread (main thread)
if (ppb_message_loop_get_for_main_thread() == 0) {
pthread_barrier_init(&aux_instance->main_thread_barrier, NULL, 2);
pthread_create(&aux_instance->main_thread, NULL, fresh_wrapper_main_thread, aux_instance);
pthread_detach(aux_instance->main_thread);
pthread_barrier_wait(&aux_instance->main_thread_barrier);
pthread_barrier_destroy(&aux_instance->main_thread_barrier);
}
fpp_config_initialize();
if (tried_files) {
g_list_free_full(tried_files, g_free);
tried_files = NULL;
}
if (fpp_config_get_plugin_path()) {
const char *ptr = fpp_config_get_plugin_path();
const char *last = strchr(ptr, ':');
uintptr_t ret;
// parse ':'-separated list
while (last != NULL) {
// try entries one by one
char *entry = strndup(ptr, last - ptr);
ret = do_load_ppp_module(entry);
free(entry);
if (ret == 0)
return 0;
ptr = last + 1;
last = strchr(ptr, ':');
}
// and the last entry
ret = do_load_ppp_module(ptr);
if (ret == 0)
return 0;
goto failure;
}
// try all paths
const char **path_list = fpp_config_get_plugin_path_list();
while (*path_list) {
gchar *fname = g_strdup_printf("%s/%s", *path_list, fpp_config_get_plugin_file_name());
uintptr_t ret = do_load_ppp_module(fname);
g_free(fname);
if (ret == 0)
return 0;
path_list ++;
}
failure:
config.quirks.plugin_missing = 1;
use_fallback_version_strings();
trace_error("%s, can't find %s\n", __func__, fpp_config_get_plugin_file_name());
return 1;
}
开发者ID:eryngion,项目名称:freshplayerplugin,代码行数:85,代码来源:np_entry.c
示例2: xdd_barrier
/* xdd_barrier() - This is the actual barrier subroutine.
* The caller will block in this subroutine until all required threads enter
* this subroutine <barrier> at which time they will all be released.
*
* The "owner" parameter indicates whether or not the calling thread is the
* owner of this barrier. 0==NOT owner, 1==owner. If this thread owns this
* barrier then it will be responsible for removing the "occupant" chain
* upon being released from this barrier.
*
* Before entering the barrier, the occupant structure is added to the end
* of the occupant chain. This allows the debug routine to see which threads
* are in a barrier at any given time as well as when they entered the barrier.
*
* If the barrier is a Target Thread or a Worker Thread then the Target_Data pointer is
* valid and the "current_barrier" member of that Target_Data is set to the barrier
* pointer of the barrier that this thread is about to enter. Upon leaving the
* barrier, this pointer is cleared.
*
* THIS SUBROUTINE IMPLEMENTS BARRIERS USING PTHREAD_BARRIERS
*/
int32_t
xdd_barrier(struct xdd_barrier *bp, xdd_occupant_t *occupantp, char owner) {
int32_t status; // Status of the pthread_barrier call
/* "threads" is the number of participating threads */
if (bp->threads == 1) return(0); /* If there is only one thread then why bother sleeping */
// Put this Target_Data on the Barrier Target_Data Chain so that we can track it later if we need to
/////// this is to keep track of which Target_Data are in a particular barrier at any given time...
pthread_mutex_lock(&bp->mutex);
// Add occupant structure here
if (bp->counter == 0) { // Add first occupant to the chain
bp->first_occupant = occupantp;
bp->last_occupant = occupantp;
occupantp->prev_occupant = occupantp;
occupantp->next_occupant = occupantp;
} else { // Add this barrier to the end of the chain
occupantp->next_occupant = bp->first_occupant; // The last one on the chain points back to the first barrier on the chain as its "next"
occupantp->prev_occupant = bp->last_occupant;
bp->last_occupant->next_occupant = occupantp;
bp->last_occupant = occupantp;
} // Done adding this barrier to the chain
if (occupantp->occupant_type & XDD_OCCUPANT_TYPE_TARGET ) {
// Put the barrier pointer into this thread's Target_Data->current_barrier
((target_data_t *)(occupantp->occupant_data))->td_current_state |= TARGET_CURRENT_STATE_BARRIER;
((target_data_t *)(occupantp->occupant_data))->td_current_barrier = bp;
} else if (occupantp->occupant_type & XDD_OCCUPANT_TYPE_WORKER_THREAD) {
// Put the barrier pointer into this thread's Worker_Data->current_barrier
((worker_data_t *)(occupantp->occupant_data))->wd_current_state |= WORKER_CURRENT_STATE_BARRIER;
((worker_data_t *)(occupantp->occupant_data))->wd_current_barrier = bp;
}
bp->counter++;
pthread_mutex_unlock(&bp->mutex);
// Now we wait here at this barrier until all the other threads arrive...
nclk_now(&occupantp->entry_time);
#ifdef HAVE_PTHREAD_BARRIER_T
status = pthread_barrier_wait(&bp->pbar);
nclk_now(&occupantp->exit_time);
if ((status != 0) && (status != PTHREAD_BARRIER_SERIAL_THREAD)) {
fprintf(xgp->errout,"%s: xdd_barrier<pthread_barriers>: ERROR: pthread_barrier_wait failed: Barrier %s, status is %d, errno is %d\n",
xgp->progname, bp->name, status, errno);
perror("Reason");
status = -1;
}
#else
status = xint_barrier_wait(&bp->pbar);
nclk_now(&occupantp->exit_time);
if (status != 0) {
fprintf(xgp->errout,"%s: xdd_barrier<pthread_barriers>: ERROR: xint_barrier_wait failed: Barrier %s, status is %d, errno is %d\n",
xgp->progname, bp->name, status, errno);
perror("Reason");
status = -1;
}
#endif
if (occupantp->occupant_type & XDD_OCCUPANT_TYPE_TARGET ) {
// Clear this thread's Target_Data->current_barrier
((target_data_t *)(occupantp->occupant_data))->td_current_barrier = NULL;
((target_data_t *)(occupantp->occupant_data))->td_current_state &= ~TARGET_CURRENT_STATE_BARRIER;
} else if (occupantp->occupant_type & XDD_OCCUPANT_TYPE_WORKER_THREAD) {
// Put the barrier pointer into this thread's Worker_Data->current_barrier
((worker_data_t *)(occupantp->occupant_data))->wd_current_barrier = NULL;
((worker_data_t *)(occupantp->occupant_data))->wd_current_state &= ~WORKER_CURRENT_STATE_BARRIER;
}
// Clear this occupant chain if we are the owner of this barrier
if (owner) {
pthread_mutex_lock(&bp->mutex);
// Clear the first/last chain pointers
bp->first_occupant = NULL;
bp->last_occupant = NULL;
bp->counter = 0;
pthread_mutex_unlock(&bp->mutex);
}
return(status);
} // End of xdd_barrier() POSIX
开发者ID:DaElf,项目名称:xdd,代码行数:99,代码来源:barrier.c
示例3: hid_open_path
//.........这里部分代码省略.........
if (!strcmp(dev_path, path)) {
/* Matched Paths. Open this device */
/* OPEN HERE */
res = libusb_open(usb_dev, &dev->device_handle);
if (res < 0) {
LOG("can't open device\n");
free(dev_path);
break;
}
good_open = 1;
#ifdef DETACH_KERNEL_DRIVER
/* Detach the kernel driver, but only if the
device is managed by the kernel */
if (libusb_kernel_driver_active(dev->device_handle, intf_desc->bInterfaceNumber) == 1) {
res = libusb_detach_kernel_driver(dev->device_handle, intf_desc->bInterfaceNumber);
if (res < 0) {
libusb_close(dev->device_handle);
LOG("Unable to detach Kernel Driver\n");
free(dev_path);
good_open = 0;
break;
}
}
#endif
res = libusb_claim_interface(dev->device_handle, intf_desc->bInterfaceNumber);
if (res < 0) {
LOG("can't claim interface %d: %d\n", intf_desc->bInterfaceNumber, res);
free(dev_path);
libusb_close(dev->device_handle);
good_open = 0;
break;
}
/* Store off the string descriptor indexes */
dev->manufacturer_index = desc.iManufacturer;
dev->product_index = desc.iProduct;
dev->serial_index = desc.iSerialNumber;
/* Store off the interface number */
dev->interface = intf_desc->bInterfaceNumber;
/* Find the INPUT and OUTPUT endpoints. An
OUTPUT endpoint is not required. */
for (i = 0; i < intf_desc->bNumEndpoints; i++) {
const struct libusb_endpoint_descriptor *ep
= &intf_desc->endpoint[i];
/* Determine the type and direction of this
endpoint. */
int is_interrupt =
(ep->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK)
== LIBUSB_TRANSFER_TYPE_INTERRUPT;
int is_output =
(ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK)
== LIBUSB_ENDPOINT_OUT;
int is_input =
(ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK)
== LIBUSB_ENDPOINT_IN;
/* Decide whether to use it for intput or output. */
if (dev->input_endpoint == 0 &&
is_interrupt && is_input) {
/* Use this endpoint for INPUT */
dev->input_endpoint = ep->bEndpointAddress;
dev->input_ep_max_packet_size = ep->wMaxPacketSize;
}
if (dev->output_endpoint == 0 &&
is_interrupt && is_output) {
/* Use this endpoint for OUTPUT */
dev->output_endpoint = ep->bEndpointAddress;
}
}
pthread_create(&dev->thread, NULL, read_thread, dev);
/* Wait here for the read thread to be initialized. */
pthread_barrier_wait(&dev->barrier);
}
free(dev_path);
}
}
}
libusb_free_config_descriptor(conf_desc);
}
libusb_free_device_list(devs, 1);
/* If we have a good handle, return it. */
if (good_open) {
return dev;
}
else {
/* Unable to open any devices. */
free_hid_device(dev);
return NULL;
}
}
开发者ID:Tieske,项目名称:hidapi,代码行数:101,代码来源:hid.c
示例4: printf
void *MavlinkStatusTask(void *ptr) {
MavlinkStruct *Mavlink = (MavlinkStruct *) ptr;
AttitudeData *AttitudeDesire = Control.AttitudeDesire;
AttitudeData *AttitudeMesure = Mavlink->AttitudeMesure;
AttData Data, Speed;
AttData DataD, SpeedD;
AttData DataM, SpeedM;
double Error[4] = {0.0, 0.0, 0.0, 0.0};
uint32_t TimeStamp;
mavlink_message_t msg;
uint16_t len;
uint8_t buf[BUFFER_LENGTH];
int bytes_sent;
uint32_t sensor = 0xf00f;
printf("%s : Mavlink Status démarré\n", __FUNCTION__);
pthread_barrier_wait(&(MavlinkStartBarrier));
while (MavlinkActivated) {
sem_wait(&MavlinkStatusTimerSem);
if (MavlinkActivated == 0)
break;
memset(buf, 0, BUFFER_LENGTH);
pthread_spin_lock(&(AttitudeMesure->AttitudeLock));
memcpy((void *) &Data, (void *) &(AttitudeMesure->Data), sizeof(AttData));
memcpy((void *) &Speed, (void *) &(AttitudeMesure->Speed), sizeof(AttData));
TimeStamp = AttitudeMesure->timestamp_s*1000 + AttitudeMesure->timestamp_n/1000000L;
pthread_spin_unlock(&(AttitudeMesure->AttitudeLock));
//Send Heartbeat
mavlink_msg_heartbeat_pack(SYSTEM_ID, COMPONENT_ID, &msg, MAV_TYPE_HELICOPTER, MAV_AUTOPILOT_GENERIC, MAV_MODE_GUIDED_ARMED, 0, MAV_STATE_ACTIVE);
len = mavlink_msg_to_send_buffer(buf, &msg);
bytes_sent = sendto(Mavlink->sock, buf, len, 0, (struct sockaddr *)&Mavlink->gcAddr, sizeof(struct sockaddr_in));
// Send Status
mavlink_msg_sys_status_pack(SYSTEM_ID, COMPONENT_ID, &msg, sensor, sensor, 0, 500, 11000, -1, -1, 0, 0, 0, 0, 0, 0);
len = mavlink_msg_to_send_buffer(buf, &msg);
bytes_sent = sendto(Mavlink->sock, buf, len, 0, (struct sockaddr *)&Mavlink->gcAddr, sizeof (struct sockaddr_in));
// Send Local Position
mavlink_msg_local_position_ned_pack(SYSTEM_ID, COMPONENT_ID, &msg, TimeStamp, 0, 0, (float) Data.Elevation, 0, 0, (float) Speed.Elevation);
len = mavlink_msg_to_send_buffer(buf, &msg);
bytes_sent = sendto(Mavlink->sock, buf, len, 0, (struct sockaddr *)&Mavlink->gcAddr, sizeof(struct sockaddr_in));
pthread_spin_lock(&(AttitudeDesire->AttitudeLock));
memcpy((void *) &DataD, (void *) &(AttitudeDesire->Data), sizeof(AttData));
memcpy((void *) &SpeedD, (void *) &(AttitudeDesire->Speed), sizeof(AttData));
pthread_spin_unlock(&(AttitudeDesire->AttitudeLock));
pthread_spin_lock(&(AttitudeMesure->AttitudeLock));
memcpy((void *) &DataM, (void *) &(AttitudeMesure->Data), sizeof(AttData));
memcpy((void *) &SpeedM, (void *) &(AttitudeMesure->Speed), sizeof(AttData));
pthread_spin_unlock(&(AttitudeMesure->AttitudeLock));
Error[HEIGHT] = DataD.Elevation - DataM.Elevation;
Error[ROLL] = DataD.Roll - DataM.Roll;
Error[PITCH] = DataD.Pitch - DataM.Pitch;
Error[YAW] = DataD.Yaw - DataM.Yaw;
// Send Attitude
mavlink_msg_attitude_pack(SYSTEM_ID, COMPONENT_ID, &msg, TimeStamp, (float) Data.Roll, (float) Data.Pitch, (float) Data.Yaw, (float) Speed.Roll, (float) Speed.Pitch, (float) Speed.Yaw);
len = mavlink_msg_to_send_buffer(buf, &msg);
bytes_sent = sendto(Mavlink->sock, buf, len, 0, (struct sockaddr *)&Mavlink->gcAddr, sizeof(struct sockaddr_in));
}
printf("%s : Mavlink Status Arrêté\n", __FUNCTION__);
pthread_exit(NULL);
}
开发者ID:limoges,项目名称:drone,代码行数:66,代码来源:Mavlink.c
示例5: do_test
static int
do_test (void)
{
pthread_mutexattr_t a;
if (pthread_mutexattr_init (&a) != 0)
{
puts ("mutexattr_init failed");
return 1;
}
if (pthread_mutexattr_setrobust (&a, PTHREAD_MUTEX_ROBUST) != 0)
{
puts ("mutexattr_setrobust failed");
return 1;
}
#ifdef ENABLE_PI
if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_INHERIT) != 0)
{
puts ("pthread_mutexattr_setprotocol failed");
return 1;
}
#endif
int e;
e = pthread_mutex_init (&m, &a);
if (e != 0)
{
#ifdef ENABLE_PI
if (e == ENOTSUP)
{
puts ("PI robust mutexes not supported");
return 0;
}
#endif
puts ("mutex_init failed");
return 1;
}
if (pthread_mutexattr_destroy (&a) != 0)
{
puts ("mutexattr_destroy failed");
return 1;
}
if (pthread_barrier_init (&b, NULL, 2) != 0)
{
puts ("barrier_init failed");
return 1;
}
#define N 5
pthread_t th[N];
for (long int n = 0; n < N; ++n)
{
if (pthread_create (&th[n], NULL, tf, (void *) n) != 0)
{
printf ("pthread_create loop %ld failed\n", n + 1);
return 1;
}
e = pthread_barrier_wait (&b);
if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
{
printf ("parent: barrier_wait failed in round %ld\n", n + 1);
return 1;
}
}
if (pthread_mutex_lock (&m) != 0)
{
puts ("parent: mutex_lock failed");
return 1;
}
if (pthread_mutex_unlock (&m) != 0)
{
puts ("parent: mutex_unlock failed");
return 1;
}
if (pthread_cond_broadcast (&c) != 0)
{
puts ("cond_broadcast failed");
return 1;
}
for (int n = 0; n < N; ++n)
{
void *res;
if (pthread_join (th[n], &res) != 0)
{
printf ("join round %d failed\n", n + 1);
return 1;
}
if (res != PTHREAD_CANCELED)
{
printf ("thread %d not canceled\n", n + 1);
return 1;
}
//.........这里部分代码省略.........
开发者ID:kostikbel,项目名称:glibc-robust-tests,代码行数:101,代码来源:tst-robust7.c
示例6: tmain
/* A worker thread receives a number and a 4-letter name via targ */
void * tmain(void * targ)
{
/* Local variables are not shared with other threads */
int no, i;
char name[5];
pthread_t tid;
int isBooked[t];//Tells how many times train i has been booked by this thread.
memset(isBooked, 0, sizeof(isBooked));
int trainsBooked[t];//Tells which all trains have been booked by this thread
int numTrainsBooked = 0;//Count of the number of trains booked by this thread
/* Retrieve my number and name from the parameter passed */
no = ((tinfo *)targ) -> tno;
strcpy(name,((tinfo *)targ) -> tname);
/* Retrieve my thread id */
tid = pthread_self();
while (1) {
/* Check for termination condition */
pthread_mutex_lock(&donemutex);
/* if the master thread is done */
if(mdone)
{
pthread_mutex_unlock(&donemutex);
pthread_barrier_wait(&barrier);
pthread_exit(NULL);
}
/* The master thread is still sleeping, so I continue to work */
pthread_mutex_unlock(&donemutex);
//Check if number of active queries is less than MAX
pthread_mutex_lock(&querymutex);
if(numActiveQueries == MAX)
{
printf("\nThread %d : Blocked since active queries = MAX\n", no);
pthread_cond_wait(&querycond, &querymutex);
}
numActiveQueries++;
pthread_mutex_unlock(&querymutex);
int a123;
//Start query
int queryType = 1 + rand()%3;
if(queryType == INQUIRE)
{
inquiry(no);
}
else if(queryType == BOOK)
{
booking(no, isBooked, trainsBooked, &numTrainsBooked);
}
else
{
cancellation(no, isBooked, trainsBooked, &numTrainsBooked);
}
pthread_mutex_lock(&querymutex);
numActiveQueries--;
if(numActiveQueries == (MAX-1))//wake up a waiting query
pthread_cond_signal(&querycond);
pthread_mutex_unlock(&querymutex);
sleep(SLEEPTIME);
}
}
开发者ID:manavs19,项目名称:operating-system,代码行数:70,代码来源:reservation.c
示例7: pthread_mutex_lock
static void *start_lock(void *arg)
{
pthread_mutex_lock(arg);
pthread_barrier_wait(&barrier2);
return 0;
}
开发者ID:andrey-gvrd,项目名称:rusl,代码行数:6,代码来源:pthread-robust-detach.c
示例8: uv_barrier_wait
int uv_barrier_wait(uv_barrier_t* barrier) {
int r = pthread_barrier_wait(barrier);
if (r && r != PTHREAD_BARRIER_SERIAL_THREAD)
abort();
return r == PTHREAD_BARRIER_SERIAL_THREAD;
}
开发者ID:26597925,项目名称:uvbook,代码行数:6,代码来源:thread.c
示例9: image
/* Do the forward Fast Fourier Transform either on two input images
(the padded image and kernel) or on one image (the multiplication
of the FFT of the two). In the second case, it is assumed that we
are looking at the complex conjugate of the array so in practice
this will be a backward transform. */
void
twodimensionfft(struct convolveparams *p, struct fftonthreadparams *fp,
int forward1backwardn1)
{
int err;
pthread_t t; /* All thread ids saved in this, not used. */
pthread_attr_t attr;
pthread_barrier_t b;
size_t i, nb, *indexs, thrdcols;
size_t nt=p->cp.numthreads, multiple=0;
/* First we are going to get the 1D fourier transform on the rows of
both images. */
if(forward1backwardn1==1) multiple=2;
else if(forward1backwardn1==-1) multiple=1;
else
error(EXIT_FAILURE, 0, "%s: a bug! The value of the variable "
"`forward1backwardn1' is %d not 1 or 2. Please contact us at %s "
"so we can find the cause of the problem and fix it", __func__,
forward1backwardn1, PACKAGE_BUGREPORT);
/* ==================== */
/* 1D FFT on each row. */
/* ==================== */
gal_threads_dist_in_threads(multiple*p->ps0, nt, &indexs, &thrdcols);
if(nt==1)
{
fp[0].stride=1;
fp[0].indexs=&indexs[0];
fp[0].forward1backwardn1=forward1backwardn1;
onedimensionfft(&fp[0]);
}
else
{
/* Initialize the attributes. Note that this running thread
(that spinns off the nt threads) is also a thread, so the
number the barrier should be one more than the number of
threads spinned off. */
if( multiple*p->ps0 < nt ) nb=multiple*p->ps0+1;
else nb=nt+1;
gal_threads_attr_barrier_init(&attr, &b, nb);
/* Spin off the threads: */
for(i=0;i<nt;++i)
if(indexs[i*thrdcols]!=GAL_BLANK_SIZE_T)
{
fp[i].id=i;
fp[i].b=&b;
fp[i].stride=1; /* On each row, stride=1 */
fp[i].indexs=&indexs[i*thrdcols];
fp[i].forward1backwardn1=forward1backwardn1;
err=pthread_create(&t, &attr, onedimensionfft, &fp[i]);
if(err)
error(EXIT_FAILURE, 0, "%s: can't create thread %zu for rows",
__func__, i);
}
/* Wait for all threads to finish and free the spaces. */
pthread_barrier_wait(&b);
pthread_attr_destroy(&attr);
pthread_barrier_destroy(&b);
}
free(indexs);
/* ====================== */
/* 1D FFT on each column. */
/* ====================== */
/* No comments, exact duplicate, except the p->ps1s! */
gal_threads_dist_in_threads(multiple*p->ps1, nt, &indexs, &thrdcols);
if(nt==1)
{
fp[0].stride=p->ps1;
fp[0].indexs=indexs;
fp[0].forward1backwardn1=forward1backwardn1;
onedimensionfft(&fp[0]);
}
else
{
if( multiple*p->ps1 < nt ) nb=multiple*p->ps1+1;
else nb=nt+1;
gal_threads_attr_barrier_init(&attr, &b, nb);
for(i=0;i<nt;++i)
if(indexs[i*thrdcols]!=GAL_BLANK_SIZE_T)
{
fp[i].b=&b;
fp[i].stride=p->ps1; /* On each column, stride is p->ps1 */
fp[i].indexs=&indexs[i*thrdcols];
fp[i].forward1backwardn1=forward1backwardn1;
err=pthread_create(&t, &attr, onedimensionfft, &fp[i]);
if(err)
error(EXIT_FAILURE, 0, "%s: can't create thread %zu for columns",
__func__, i);
//.........这里部分代码省略.........
开发者ID:VladimirMarkelov,项目名称:gnuastro-vvm,代码行数:101,代码来源:convolve.c
示例10: do_one_test
static int
do_one_test (void)
{
in_sh_body = 0;
cleanups = 0;
if (pipe (fd) != 0 || pipe (fd + 2) != 0)
{
puts ("pipe failed");
return 1;
}
pthread_t th;
if (pthread_create (&th, NULL, tf, NULL) != 0)
{
puts ("create failed");
return 1;
}
int r = pthread_barrier_wait (&b);
if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
{
puts ("parent thread: barrier_wait failed");
return 1;
}
sleep (1);
r = pthread_kill (th, SIGHUP);
if (r)
{
errno = r;
printf ("pthread_kill failed %m\n");
return 1;
}
while (in_sh_body == 0)
sleep (1);
if (pthread_cancel (th) != 0)
{
puts ("cancel failed");
return 1;
}
/* This will cause the read in the child to return. */
close (fd[0]);
close (fd[1]);
close (fd[2]);
close (fd[3]);
void *ret;
if (pthread_join (th, &ret) != 0)
{
puts ("join failed");
return 1;
}
if (ret != PTHREAD_CANCELED)
{
puts ("result is wrong");
return 1;
}
if (cleanups != 0x1234L)
{
printf ("called cleanups %lx\n", cleanups);
return 1;
}
return 0;
}
开发者ID:AdvancedC,项目名称:glibc,代码行数:71,代码来源:tst-cancel20.c
示例11: tf
static void *
tf (void *arg)
{
pthread_t th = (pthread_t) arg;
int r = pthread_barrier_wait (&b);
if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
{
puts ("parent thread: barrier_wait failed");
exit (1);
}
sleep (1);
r = pthread_kill (th, SIGHUP);
if (r)
{
errno = r;
printf ("pthread_kill failed %m\n");
exit (1);
}
while (in_sh_body == 0)
sleep (1);
if (pthread_cancel (th) != 0)
{
puts ("cancel failed");
exit (1);
}
/* This will cause the read in the initial thread to return. */
close (fd[0]);
close (fd[1]);
close (fd[2]);
close (fd[3]);
void *ret;
if (pthread_join (th, &ret) != 0)
{
puts ("join failed");
exit (1);
}
if (ret != PTHREAD_CANCELED)
{
puts ("result is wrong");
exit (1);
}
if (cleanups != 0x1234L)
{
printf ("called cleanups %lx\n", cleanups);
exit (1);
}
if (pthread_barrier_destroy (&b))
{
puts ("barrier destroy failed");
exit (1);
}
exit (0);
}
开发者ID:LinuxUser404,项目名称:smack-glibc,代码行数:64,代码来源:tst-cancel21.c
示例12: hid_open_path
hid_device * HID_API_EXPORT hid_open_path(const char *path)
{
int i;
hid_device *dev = NULL;
CFIndex num_devices;
dev = new_hid_device();
/* Set up the HID Manager if it hasn't been done */
if (hid_init() < 0)
return NULL;
/* give the IOHIDManager a chance to update itself */
process_pending_events();
CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr);
num_devices = CFSetGetCount(device_set);
IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
CFSetGetValues(device_set, (const void **) device_array);
for (i = 0; i < num_devices; i++) {
char cbuf[BUF_LEN];
size_t len;
IOHIDDeviceRef os_dev = device_array[i];
len = make_path(os_dev, cbuf, sizeof(cbuf));
if (!strcmp(cbuf, path)) {
/* Matched Paths. Open this Device. */
IOReturn ret = IOHIDDeviceOpen(os_dev, kIOHIDOptionsTypeSeizeDevice);
if (ret == kIOReturnSuccess) {
char str[32];
free(device_array);
CFRetain(os_dev);
CFRelease(device_set);
dev->device_handle = os_dev;
/* Create the buffers for receiving data */
dev->max_input_report_len = (CFIndex) get_max_report_length(os_dev);
dev->input_report_buf = calloc(dev->max_input_report_len, sizeof(uint8_t));
/* Create the Run Loop Mode for this device.
printing the reference seems to work. */
sprintf(str, "HIDAPI_%p", os_dev);
dev->run_loop_mode =
CFStringCreateWithCString(NULL, str, kCFStringEncodingASCII);
/* Attach the device to a Run Loop */
IOHIDDeviceRegisterInputReportCallback(
os_dev, dev->input_report_buf, dev->max_input_report_len,
&hid_report_callback, dev);
IOHIDDeviceRegisterRemovalCallback(dev->device_handle, hid_device_removal_callback, dev);
/* Start the read thread */
pthread_create(&dev->thread, NULL, read_thread, dev);
/* Wait here for the read thread to be initialized. */
pthread_barrier_wait(&dev->barrier);
return dev;
}
else {
goto return_error;
}
}
}
return_error:
free(device_array);
CFRelease(device_set);
free_hid_device(dev);
return NULL;
}
开发者ID:Cloudhomebr,项目名称:node-openzwave,代码行数:73,代码来源:hid.c
示例13: IOHIDDeviceScheduleWithRunLoop
static void *read_thread(void *param)
{
hid_device *dev = param;
SInt32 code;
/* Move the device's run loop to this thread. */
IOHIDDeviceScheduleWithRunLoop(dev->device_handle, CFRunLoopGetCurrent(), dev->run_loop_mode);
/* Create the RunLoopSource which is used to signal the
event loop to stop when hid_close() is called. */
CFRunLoopSourceContext ctx;
memset(&ctx, 0, sizeof(ctx));
ctx.version = 0;
ctx.info = dev;
ctx.perform = &perform_signal_callback;
dev->source = CFRunLoopSourceCreate(kCFAllocatorDefault, 0/*order*/, &ctx);
CFRunLoopAddSource(CFRunLoopGetCurrent(), dev->source, dev->run_loop_mode);
/* Store off the Run Loop so it can be stopped from hid_close()
and on device disconnection. */
dev->run_loop = CFRunLoopGetCurrent();
/* Notify the main thread that the read thread is up and running. */
pthread_barrier_wait(&dev->barrier);
/* Run the Event Loop. CFRunLoopRunInMode() will dispatch HID input
reports into the hid_report_callback(). */
while (!dev->shutdown_thread && !dev->disconnected) {
code = CFRunLoopRunInMode(dev->run_loop_mode, 1000/*sec*/, FALSE);
/* Return if the device has been disconnected */
if (code == kCFRunLoopRunFinished) {
dev->disconnected = 1;
break;
}
/* Break if The Run Loop returns Finished or Stopped. */
if (code != kCFRunLoopRunTimedOut &&
code != kCFRunLoopRunHandledSource) {
/* There was some kind of error. Setting
shutdown seems to make sense, but
there may be something else more appropriate */
dev->shutdown_thread = 1;
break;
}
}
/* Now that the read thread is stopping, Wake any threads which are
waiting on data (in hid_read_timeout()). Do this under a mutex to
make sure that a thread which is about to go to sleep waiting on
the condition acutally will go to sleep before the condition is
signaled. */
pthread_mutex_lock(&dev->mutex);
pthread_cond_broadcast(&dev->condition);
pthread_mutex_unlock(&dev->mutex);
/* Wait here until hid_close() is called and makes it past
the call to CFRunLoopWakeUp(). This thread still needs to
be valid when that function is called on the other thread. */
pthread_barrier_wait(&dev->shutdown_barrier);
return NULL;
}
开发者ID:Cloudhomebr,项目名称:node-openzwave,代码行数:63,代码来源:hid.c
示例14: while
//.........这里部分代码省略.........
surround[0].x = working_list[i].x;
surround[0].y = working_list[i].y - 1;
}
//find the right position
if(working_list[i].x + 1 < size)
{
surround[1].value = matrix[position + 1];
surround[1].x = working_list[i].x + 1;
surround[1].y = working_list[i].y;
}
//find bottom position
if(position + size < size * size)
{
surround[2].value = matrix[position + size];
surround[2].x = working_list[i].x;
surround[2].y = working_list[i].y + 1;
}
//find left position
if(working_list[i].x - 1 >= 0)
{
surround[3].value = matrix[position - 1];
surround[3].x = working_list[i].x - 1;
surround[3].y = working_list[i].y;
}
//find the minimum among the surrounding positions
int j;
for(j = 0; j < 4; j++)
{
//set min to the new position
if(surround[j].value != -1 && surround[j].value < local_min.value)
{
local_min.value = surround[j].value;
local_min.x = surround[j].x;
local_min.y = surround[j].y;
}
}
//determine if the local min is smaller than the minimum found so far
if(local_min.value < min_cells[thread_id].value)
{
min_cells[thread_id] = local_min;
}
local_min.value = INT_MAX;
local_min.x = -1;
local_min.y = -1;
}
//BARRIER: Wait for all other threads to find their minimum cell
pthread_barrier_wait(&barrier);
//Thread 0 manages the matrix, mask, working list, and filled cell count
if(thread_id == 0)
{
pos global_min;
global_min.value = INT_MAX;
global_min.x = -1;
global_min.y = -1;
//determine minimum cell
int k;
for(k = 0; k < num_threads; k++)
{
if(min_cells[k].value < global_min.value) //set new min
{
global_min = min_cells[k];
}
}
//determine linear position of cell
int position = size * global_min.y + global_min.x;
//fill the cell in the mask
mask[position] = 1;
//set the value in the matrix to "used"
matrix[position] = -1;
//add latest cell to the working list
working_list[filled] = global_min;
//count one more cell filled
filled++;
int m;
for(m = 0; m < num_threads; m++)
{
min_cells[m].value = INT_MAX;
min_cells[m].x = -1;
min_cells[m].y = -1;
}
}
//BARRIER: All other threads wait for Thread 0 to finish working
pthread_barrier_wait(&barrier);
}
}
开发者ID:jdeters,项目名称:BenchTest,代码行数:101,代码来源:invperc.c
示例15: check_threads
static void
check_threads (pthread_barrier_t *barrier)
{
pthread_barrier_wait (barrier);
}
开发者ID:5kg,项目名称:gdb,代码行数:5,代码来源:py-inferior.c
示例16: sender
void* sender(void* id) {
sleep(1);
pthread_barrier_wait(&bar);
pthread_kill(*((pthread_t*)id), SIGALRM);
return NULL;
}
开发者ID:koolhazz,项目名称:rr,代码行数:6,代码来源:threads.c
示例17: do_test
static int
do_test (void)
{
if (pthread_barrier_init (&b, NULL, N + 1) != 0)
{
puts ("barrier_init failed");
return 1;
}
pthread_mutex_lock (&mut);
int i, j, err;
pthread_t th[N];
for (i = 0; i < N; ++i)
if ((err = pthread_create (&th[i], NULL, tf, NULL)) != 0)
{
printf ("cannot create thread %d: %s\n", i, strerror (err));
return 1;
}
for (i = 0; i < ROUNDS; ++i)
{
pthread_cond_wait (&cond2, &mut);
if (i & 1)
pthread_mutex_unlock (&mut);
if (i & 2)
pthread_cond_broadcast (&cond);
else if (i & 4)
for (j = 0; j < N; ++j)
pthread_cond_signal (&cond);
else
{
for (j = 0; j < (i / 8) % N; ++j)
pthread_cond_signal (&cond);
pthread_cond_broadcast (&cond);
}
if ((i & 1) == 0)
pthread_mutex_unlock (&mut);
err = pthread_cond_destroy (&cond);
if (err)
{
printf ("pthread_cond_destroy failed: %s\n", strerror (err));
return 1;
}
/* Now clobber the cond variable which has been successfully
destroyed above. */
memset (&cond, (char) i, sizeof (cond));
err = pthread_barrier_wait (&b);
if (err != 0 && err != PTHREAD_BARRIER_SERIAL_THREAD)
{
puts ("parent: barrier_wait failed");
return 1;
}
pthread_mutex_lock (&mut);
err = pthread_barrier_wait (&b);
if (err != 0 && err != PTHREAD_BARRIER_SERIAL_THREAD)
{
puts ("parent: barrier_wait failed");
return 1;
}
count = 0;
err = pthread_cond_init (&cond, NULL);
if (err)
{
printf ("pthread_cond_init failed: %s\n", strerror (err));
return 1;
}
}
for (i = 0; i < N; ++i)
if ((err = pthread_join (th[i], NULL)) != 0)
{
printf ("failed to join thread %d: %s\n", i, strerror (err));
return 1;
}
puts ("done");
return 0;
}
开发者ID:Xilinx,项目名称:eglibc,代码行数:89,代码来源:tst-cond20.c
示例18: masterThread
void *
masterThread (void * arg)
{
int dither = (int)(size_t)arg;
timeout = (int)(size_t)arg;
pthread_barrier_wait(&startBarrier);
do
{
int sleepTime;
assert(pthread_mutex_lock(&control.mx) == 0);
control.value = timeout;
assert(pthread_mutex_unlock(&control.mx) == 0);
/*
* We are attempting to send the signal close to when the slave
* is due to timeout. We feel around by adding some [non-random] dither.
*
* dither is in the range 2*timeout peak-to-peak
* sleep time is the average of timeout plus dither.
* e.g.
* if timeout = 10 then dither = 20 and
* sleep millisecs is: 5 <= ms <= 15
*
* The bias value attempts to apply some negative feedback to keep
* the ratio of timeouts to signals taken close to 1:1.
* bias changes more slowly than dither so as to average more.
*
* Finally, if abs(bias) exceeds timeout then timeout is incremented.
*/
if (signalsSent % timeout == 0)
{
if (timeoutCount > signalsTakenCount)
{
bias++;
}
else if (timeoutCount < signalsTakenCount)
{
bias--;
}
if (bias < -timeout || bias > timeout)
{
timeout++;
}
}
dither = (dither + 1 ) % (timeout * 2);
sleepTime = (timeout - bias + dither) / 2;
Sleep(sleepTime);
assert(pthread_cond_signal(&control.cv) == 0);
signalsSent++;
pthread_barrier_wait(&holdBarrier);
pthread_barrier_wait(&readyBarrier);
}
while (!allExit);
return NULL;
}
开发者ID:VFR-maniac,项目名称:pthreads-win32,代码行数:61,代码来源:stress1.c
示例19: malloc
void *compute(void *s){
int pnum = *((int *) s);
double *resultArray = (double *) malloc(numberofRows * sizeof(double));
double *normalValue = (double *) malloc(2 * sizeof(double));
int c, i;
// int a = 0;
struct row *pData;
double partitionSum = 0;
normalValue[1] = 0;
pData = &partitionedMatrixData[pnum];
// totalSumAtEachPartition[pnum] = 0;
do {
//pData = &partitionedMatrixData[pnum];
partitionSum = 0;
for (c=0; c < pData->rcount; c++) {
double rowSum = 0;
//Loop through each column
for (i=0; i < pData->rowary[c].vcount; i++) {
//printf("pData->rowary[c].col[i]: %li\n", pData->rowary[c].col[i] + (pData->rowary[c].col[i]*255));
// rowSum = rowSum + (pData->rowary[c].values[i] * multiplyArray[pData->rowary[c].col[i] + (pData->rowary[c].col[i]*50)]);
rowSum = rowSum + (pData->rowary[c].values[i] * multiplyArray[pData->rowary[c].col[i]]);
}
resultArray[pData->rowary[c].rowId] = rowSum;
partitionSum = partitionSum + pow(ro
|
请发表评论