• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pthread_condattr_setpshared函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中pthread_condattr_setpshared函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_condattr_setpshared函数的具体用法?C++ pthread_condattr_setpshared怎么用?C++ pthread_condattr_setpshared使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pthread_condattr_setpshared函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char* argv[]) {
    pid_t child_id;

    //shared memory

    key_t memKey = 6655; /* A key to access shared memory segments */
    int memSize = sizeof(SharedMem);
    int memFlag = 1023; /* Call permissions and modes are set. */
    sharingMemory(memKey, memSize, memFlag);

    /*shared mutex*/
    pthread_mutexattr_t attr1, attr2;
    pthread_mutexattr_setpshared (&attr1, PTHREAD_PROCESS_SHARED);
    pthread_mutexattr_setpshared (&attr2, PTHREAD_PROCESS_SHARED);
    pthread_mutex_init (&shmem_ptr->lock, &attr1);
    pthread_mutex_init (&shmem_ptr->lock2, &attr2);

    /*shared conditions*/
    pthread_condattr_t spaceAttr, itemAttr;
    pthread_condattr_setpshared(&spaceAttr, PTHREAD_PROCESS_SHARED);
    pthread_condattr_setpshared(&itemAttr, PTHREAD_PROCESS_SHARED);
    pthread_cond_init(&shmem_ptr->SpaceAvailable, &spaceAttr);
    pthread_cond_init(&shmem_ptr->ItemAvailable, &itemAttr);

    //split code

    if ((child_id = fork()) == -1) {
        printf("Could not fork()\n");
        exit(1);
    }
    if (child_id != 0) { //consumer
      pid_t child2_id;
      if ((child2_id = fork()) == -1) {
          printf("Could not fork()\n");
          exit(1);
      }
      if(child2_id != 0){ //consumer
          char keystr[10];
          sprintf(keystr,"%d", memKey);
          execl("./consum", "consum", keystr, NULL);
          /* done with the program, so detach the shared segment and terminate */
          shmdt ( (void *)  shmem_ptr);
          printf("Finished execution \n");
      }else{ //pblack
          char keystr[10];
          sprintf(keystr,"%d", memKey);
          execl("./pBlack", "pBlack", keystr, NULL);
      }
    }else{ //pgreen
        char keystr[10];
        sprintf(keystr,"%d", memKey);
        execl("./pGreen", "pGreen", keystr, NULL);
    }


    return 0;
}
开发者ID:miguelpfitscher,项目名称:OS,代码行数:57,代码来源:main.c


示例2: create_shm_channel

shm_data* create_shm_channel(char* fldes) {
		shm_unlink(fldes);
//		fprintf(stdout, "fldes is: %s.\n", fldes);
        int shm_fldes = shm_open(fldes, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
        if (shm_fldes < 0) {
                fprintf(stderr, "Error %d (%s) on server proxy shm_open.\n", errno, strerror(errno));
				fflush(stdout);
 //               exit(1);
        }

        ftruncate(shm_fldes, segment_size);
        shm_data* mem = mmap(NULL, segment_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fldes, 0);
        close(shm_fldes);

        if(mem->file_length != 0 || mem->bytes_written != 0) {
          fprintf(stderr, "shared memory segment should have been set zero.\n");
		  fflush(stdout);
   //       exit(1);
        }


        mem->file_length = 0;
        mem->bytes_written = 0;

// initialize shared memory mutex and condition variables		
		
        pthread_mutexattr_t memory_attr;
		pthread_mutexattr_init(&memory_attr);
        pthread_mutexattr_setpshared(&memory_attr, PTHREAD_PROCESS_SHARED);
        pthread_mutex_init(&mem->data_mutex, &memory_attr);
		
		pthread_mutexattr_t filelen_attr;
		pthread_mutexattr_init(&filelen_attr);
        pthread_mutexattr_setpshared(&filelen_attr, PTHREAD_PROCESS_SHARED);
        pthread_mutex_init(&mem->file_len_mutex, &filelen_attr);
		
        pthread_condattr_t cache_attr;
		pthread_condattr_init(&cache_attr);
        pthread_condattr_setpshared(&cache_attr, PTHREAD_PROCESS_SHARED);
        pthread_cond_init(&mem->cache_cond, &cache_attr);
		
		pthread_condattr_t proxy_attr;
		pthread_condattr_init(&proxy_attr);
        pthread_condattr_setpshared(&proxy_attr, PTHREAD_PROCESS_SHARED);
        pthread_cond_init(&mem->proxy_cond, &proxy_attr);
        
        return mem;
}
开发者ID:kevinajordan,项目名称:CS8803_Introduction_to_OS,代码行数:48,代码来源:handle_with_cache.c


示例3: barrier_init

int barrier_init(barrier_t *barrier,int needed)
{
    barrier->needed = needed;
    barrier->called = 0;

	if(with_fork){
		pthread_condattr_t cattr;
		pthread_mutexattr_t mattr;

		pthread_mutexattr_init(&mattr);
		if(pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED)){
			perror("Mutex PTHREAD_PROCESS_SHARED");
			exit(1);
		}

	    pthread_condattr_init(&cattr);
		if(pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED)){
			perror("Cond PTHREAD_PROCESS_SHARED");
			exit(1);
		}

		pthread_mutex_init(&barrier->mutex,&mattr);
	    pthread_cond_init(&barrier->cond, &cattr);
	}else{
	    pthread_mutex_init(&barrier->mutex,NULL);
	    pthread_cond_init(&barrier->cond,NULL);
	}
    return 0;
}
开发者ID:formyfamily,项目名称:ski,代码行数:29,代码来源:ski-barriers.c


示例4: create_locks

static ledger_status create_locks(ledger_partition *partition, int fd) {
    ledger_status rc;
    ledger_partition_locks locks;
    pthread_mutexattr_t mattr;
    pthread_condattr_t cattr;

    rc = pthread_mutexattr_init(&mattr);
    ledger_check_rc(rc == 0, LEDGER_ERR_GENERAL, "Failed to initialize mutex attribute");

    rc = pthread_condattr_init(&cattr);
    ledger_check_rc(rc == 0, LEDGER_ERR_GENERAL, "Failed to initialize cond attribute");

    rc = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
    ledger_check_rc(rc == 0, LEDGER_ERR_GENERAL, "Failed to set mutex attribute to shared");

    rc = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
    ledger_check_rc(rc == 0, LEDGER_ERR_GENERAL, "Failed to set cond attribute to shared");

    rc = pthread_mutex_init(&locks.rotate_lock, &mattr);
    ledger_check_rc(rc == 0, LEDGER_ERR_GENERAL, "Failed to initialize journal rotate mutex");

    rc = pthread_cond_init(&locks.rotate_cond, &cattr);
    ledger_check_rc(rc == 0, LEDGER_ERR_GENERAL, "Failed to initialize journal rotate cond");

    rc = ledger_pwrite(fd, (void *)&locks, sizeof(ledger_partition_locks), 0);
    ledger_check_rc(rc, LEDGER_ERR_IO, "Failed to write meta number of entries");

    return LEDGER_OK;

error:
    return rc;
}
开发者ID:blakesmith,项目名称:ledgerd,代码行数:32,代码来源:partition.c


示例5: TEST

TEST(pthread, pthread_cond_broadcast__preserves_condattr_flags) {
#if defined(__BIONIC__) // This tests a bionic implementation detail.
  pthread_condattr_t attr;
  pthread_condattr_init(&attr);

  ASSERT_EQ(0, pthread_condattr_setclock(&attr, CLOCK_MONOTONIC));
  ASSERT_EQ(0, pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED));

  pthread_cond_t cond_var;
  ASSERT_EQ(0, pthread_cond_init(&cond_var, &attr));

  ASSERT_EQ(0, pthread_cond_signal(&cond_var));
  ASSERT_EQ(0, pthread_cond_broadcast(&cond_var));

  attr = static_cast<pthread_condattr_t>(cond_var.value);
  clockid_t clock;
  ASSERT_EQ(0, pthread_condattr_getclock(&attr, &clock));
  ASSERT_EQ(CLOCK_MONOTONIC, clock);
  int pshared;
  ASSERT_EQ(0, pthread_condattr_getpshared(&attr, &pshared));
  ASSERT_EQ(PTHREAD_PROCESS_SHARED, pshared);
#else // __BIONIC__
  GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
开发者ID:nick0lay,项目名称:platform_bionic,代码行数:25,代码来源:pthread_test.cpp


示例6: uv_cond_init

int uv_cond_init(uv_cond_t* cond) {
  pthread_condattr_t attr;

  if (pthread_condattr_init(&attr))
    return -1;
#ifndef __ANDROID__
  if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
#else
  if (pthread_condattr_setpshared(&attr, CLOCK_MONOTONIC))
#endif
    goto error2;

  if (pthread_cond_init(cond, &attr))
    goto error2;

  if (pthread_condattr_destroy(&attr))
    goto error;

  return 0;

error:
  pthread_cond_destroy(cond);
error2:
  pthread_condattr_destroy(&attr);
  return -1;
}
开发者ID:559210,项目名称:libpomelo,代码行数:26,代码来源:thread.c


示例7: init_ring_buffer

void init_ring_buffer(struct ring_buffer* rbuff) {
  rbuff->request_writes = 0;
  rbuff->request_reads = 0;

  rbuff->response_writes = 0;
  rbuff->response_reads = 0;

  pthread_mutexattr_t mattr;
  pthread_mutexattr_init(&mattr);
  pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);  
  pthread_mutex_init(&rbuff->data_mutex, &mattr);
  
  pthread_condattr_t  cattr;
  pthread_condattr_init(&cattr);
  pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
  pthread_cond_init(&rbuff->nonempty, &cattr);
  

  int i;
  for(i = 0; i < MAXSIZE; i++) {
    pthread_cond_init(&rbuff->response_ready[i], &cattr);
    rbuff->buffer[i].request_client.response = i;
  }

}
开发者ID:jedivind,项目名称:xen,代码行数:25,代码来源:ringbuffer.c


示例8: epicsMutexOsdCreate

epicsMutexOSD * epicsMutexOsdCreate(void) {
    epicsMutexOSD *pmutex;
    int           status;

    pmutex = callocMustSucceed(1, sizeof(*pmutex), "epicsMutexOsdCreate");
    status = pthread_mutexattr_init(&pmutex->mutexAttr);
    checkStatusQuit(status, "pthread_mutexattr_init", "epicsMutexOsdCreate");

#if defined _POSIX_THREAD_PRIO_INHERIT
    status = pthread_mutexattr_setprotocol(
        &pmutex->mutexAttr,PTHREAD_PRIO_INHERIT);
    if (errVerbose) checkStatus(status, "pthread_mutexattr_setprotocal");
#endif /*_POSIX_THREAD_PRIO_INHERIT*/

    status = pthread_mutex_init(&pmutex->lock, &pmutex->mutexAttr);
    checkStatusQuit(status, "pthread_mutex_init", "epicsMutexOsdCreate");

#if defined _POSIX_THREAD_PROCESS_SHARED
    status = pthread_condattr_init(&pmutex->condAttr);
    checkStatus(status, "pthread_condattr_init");
    status = pthread_condattr_setpshared(&pmutex->condAttr,
        PTHREAD_PROCESS_PRIVATE);
    checkStatus(status, "pthread_condattr_setpshared");
    status = pthread_cond_init(&pmutex->waitToBeOwner, &pmutex->condAttr);
#else
    status = pthread_cond_init(&pmutex->waitToBeOwner, 0);
#endif /*_POSIX_THREAD_PROCESS_SHARED*/
    checkStatusQuit(status, "pthread_cond_init", "epicsMutexOsdCreate");
    return pmutex;
}
开发者ID:ukaea,项目名称:epics,代码行数:30,代码来源:osdMutex.c


示例9: shm_init_header

/* init shm header */
void shm_init_header( ssm_header *header, int data_size, int history_num, ssmTimeT cycle )
{
	pthread_mutexattr_t mattr;
	pthread_condattr_t cattr; 

	header->tid_top = SSM_TID_SP - 1;	/* 初期位置 */
	header->size = data_size;	/* データサイズ */
	header->num = history_num;	/* 履歴数 */
	//header->table_size = hsize;	/* テーブルサイズ */
	header->cycle = cycle;	/* データ最小サイクル */
	header->data_off = sizeof( ssm_header );	/* データの先頭アドレス */
	header->times_off = header->data_off + ( data_size * history_num );	/* 時刻の先頭アドレス */
	//header->table_off = header->times_off + sizeof( ssmTimeT ) * hsize ;	/* time tableの先頭アドレス */
	
	/* 同期用mutexの初期化 */
	pthread_mutexattr_init(&mattr);
	pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
	pthread_mutex_init(&header->mutex, &mattr); 

	pthread_condattr_init(&cattr);
	pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
	pthread_cond_init(&header->cond, &cattr);
	
	pthread_mutexattr_destroy( &mattr );
	pthread_condattr_destroy( &cattr );
}
开发者ID:anjinkristou,项目名称:SSM,代码行数:27,代码来源:libssm-shm.c


示例10: main

int main(){
	
	pthread_mutexattr_t mutex_attr;
	pthread_condattr_t cond_attr;
	buffer.occupied = buffer.nextin = buffer.nextout = 0;
	
	pthread_mutexattr_init(&mutex_attr);
	pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED);
	pthread_mutex_init(&buffer.lock, &mutex_attr);
	
	pthread_condattr_init(&cond_attr);
	pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED);
	pthread_cond_init(&buffer.less, &cond_attr);
	pthread_cond_init(&buffer.more, &cond_attr);
	
	
	pthread_t cons, prod;
	int idCons = 0, idProd = 1;
	
	pthread_create(&cons, NULL, (void *) conscons, (void *) &idCons);
	pthread_create(&prod, NULL, (void *) prodprod, (void *) &idProd);
	
	pthread_join(cons, NULL);
	pthread_join(prod, NULL);
	
	return 0;
}
开发者ID:diega,项目名称:tp-sistemas-operativos,代码行数:27,代码来源:threads.c


示例11: mCounter

CBinarySemaphore::CBinarySemaphore(bool isFull, bool isProcessShared) : mCounter(1)
{
	Int32 retVal;
	pthread_mutexattr_t mutexAttr;
	retVal = pthread_mutexattr_init(&mutexAttr);
	sAssertion(0 == retVal, "(CBinarySemaphore::CBinarySemaphore()) : Failed to init Mutex-Attribute!");

	retVal = pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK);
	sAssertion(0 == retVal, "(CBinarySemaphore::CBinarySemaphore()) : Failed to set Mutex-Type!");

	retVal = pthread_mutex_init(&mMutex, &mutexAttr);
	sAssertion(0 == retVal, "(CBinarySemaphore::CBinarySemaphore()) : Failed to init Mutex!");

	retVal = pthread_mutexattr_destroy(&mutexAttr);
	sAssertion(0 == retVal, "(CBinarySemaphore::CBinarySemaphore()) : Failed to destroy Mutex-Attribute!");

	pthread_condattr_t conditionAttr;
	retVal = pthread_condattr_init(&conditionAttr);
	sAssertion(0 == retVal, "(CBinarySemaphore::CBinarySemaphore()) : Failed to init Condition-Attribute!");

	retVal = pthread_condattr_setpshared(&conditionAttr,
										 isProcessShared ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE);
	sAssertion(0 == retVal, "(CBinarySemaphore::CBinarySemaphore()) : Failed to set Condition-Attribute!");

	pthread_cond_init(&mCondition, &conditionAttr);
	pthread_condattr_destroy(&conditionAttr);


	if(false == isFull)
	{
		mCounter = 0;
	}
}
开发者ID:HSKA-CuBa,项目名称:CuBa_git,代码行数:33,代码来源:CBinarySemaphore.cpp


示例12: fifo_init

int fifo_init(struct fifo *fifo, size_t size, bool_t prio_inherit) {
#if defined(HAVE_LIBPTHREAD) && !defined(SDL_FIFOS)

#ifndef _POSIX_THREAD_PROCESS_SHARED
#error "no _POSIX_THREAD_PROCESS_SHARED"
#endif /* _POSIX_THREAD_PROCESS_SHARED */

	/* linux multi-process locking */
	pthread_mutexattr_t mutex_attr;
	pthread_condattr_t cond_attr;
	struct utsname utsname;
	int err;

	if ((err = pthread_mutexattr_init(&mutex_attr)) < 0) {
		return err;
	}
	if (prio_inherit) {
		if ((err = pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED)) < 0) {
			return err;
		}
#ifdef _POSIX_THREAD_PRIO_INHERIT
		/* only on PREEMPT kernels */
		if ((err = uname(&utsname)) < 0) {
			return err;
		}
		if (!RUNNING_ON_VALGRIND && strstr(utsname.version, "PREEMPT") != NULL) {
			if ((err = pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT)) < 0) {
				return err;
			}
		}
#endif /* _POSIX_THREAD_PRIO_INHERIT */
	}
	if ((err = pthread_mutex_init(&fifo->mutex, &mutex_attr)) < 0) {
		return err;
	}

	if ((err = pthread_condattr_init(&cond_attr)) < 0) {
		return err;
	}
	if (prio_inherit) {
		if ((err = pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED)) < 0) {
			return err;
		}
	}
	if ((err = pthread_cond_init(&fifo->cond, &cond_attr)) < 0) {
		return err;
	}
#else
	/* cross platform locks */
	fifo->mutex = SDL_CreateMutex();
	fifo->cond = SDL_CreateCond();
#endif
	fifo->rptr = 0;
	fifo->wptr = 0;
	fifo->size = size;

	return 0;
}
开发者ID:gnalbandian,项目名称:squeezeplay,代码行数:58,代码来源:fifo.c


示例13: os_condInit

/** \brief Initialize the condition variable taking the condition
 *         attributes into account
 *
 * \b os_condInit calls \b pthread_cond_init to intialize the posix condition
 * variable.
 *
 * In case the scope attribute is \b OS_SCOPE_SHARED, the posix
 * condition variable "pshared" attribute is set to \b PTHREAD_PROCESS_SHARED
 * otherwise it is set to \b PTHREAD_PROCESS_PRIVATE.
 */
os_result
os_condInit (
    os_cond *cond, 
    os_mutex *dummymtx,
    const os_condAttr *condAttr)
{
    pthread_condattr_t mattr;
    int result = 0;
    os_result rv;

    assert (cond != NULL);
    assert (condAttr != NULL);

#ifdef OSPL_STRICT_MEM
   assert(cond->signature != OS_COND_MAGIC_SIG);
#endif

    pthread_condattr_init (&mattr);
    if (condAttr->scopeAttr == OS_SCOPE_SHARED) {
        result = pthread_condattr_setpshared (&mattr, PTHREAD_PROCESS_SHARED);
    } else {
        result = pthread_condattr_setpshared (&mattr, PTHREAD_PROCESS_PRIVATE);
    }
    if (result == 0) {
#ifdef OSPL_STRICT_MEM
       result = pthread_cond_init (&cond->cond, &mattr);
#else
       result = pthread_cond_init (cond, &mattr);
       if (result == EBUSY) {
          os_condDestroy (cond);
          result = pthread_cond_init (cond, &mattr);
       }
#endif
    }
    pthread_condattr_destroy (&mattr);
    if (result == 0) {
#ifdef OSPL_STRICT_MEM
        cond->signature = OS_COND_MAGIC_SIG;
#endif
	rv = os_resultSuccess;
    } else {
	rv = os_resultFail;
    }
    return rv;
}
开发者ID:xrl,项目名称:opensplice_dds,代码行数:55,代码来源:os_cond.c


示例14: Pthread_condattr_setpshared

void Pthread_condattr_setpshared(pthread_condattr_t * attr, int flag)
{
	int n;

	if ((n = pthread_condattr_setpshared(attr, flag)) == 0)
		return;
	errno = n;
	fprintf(stderr, "pthread_condattr_setpshared error");
}
开发者ID:iloveloveyou,项目名称:chirico,代码行数:9,代码来源:wrapper.c


示例15: pthread_cond_init_shared

int pthread_cond_init_shared ( pthread_cond_t **cond_p )
{
	static pthread_cond_t cond_initial = PTHREAD_COND_INITIALIZER;
	*cond_p = shm_malloc ( sizeof ( **cond_p ) );
	memcpy ( *cond_p, &cond_initial, sizeof ( cond_initial ) );
	pthread_condattr_t attr;
	pthread_condattr_init ( &attr );
	pthread_condattr_setpshared ( &attr, PTHREAD_PROCESS_SHARED );
	return pthread_cond_init ( *cond_p, &attr );
}
开发者ID:xaionaro,项目名称:kvm-pool,代码行数:10,代码来源:pthreadex.c


示例16: init_sync

void init_sync(struct Sync* sync) {
	// These structures are used to initialize mutexes
	// and condition variables. We will use them to set
	// the PTHREAD_PROCESS_SHARED attribute, which enables
	// more than one process (and any thread in any of those
	// processes) to access the mutex and condition variable.
	pthread_mutexattr_t mutex_attributes;
	pthread_condattr_t condition_attributes;

	// These methods initialize the attribute structures
	// with default values so that we must only change
	// the one we are interested in.
	if (pthread_mutexattr_init(&mutex_attributes) != 0) {
		throw("Error initializing mutex attributes");
	}
	if (pthread_condattr_init(&condition_attributes) != 0) {
		throw("Error initializing condition variable attributes");
	}

	// Here we set the "process-shared"-attribute of the mutex
	// and condition variable to PTHREAD_PROCESS_SHARED. This
	// means multiple processes may access these objects. If
	// we wouldn't do this, the attribute would be PTHREAD_PROCESS
	// _PRIVATE, where only threads created by the process who
	// initialized the objects would be allowed to access them.
	// By passing PTHREAD_PROCESS_SHARED the objects may also live
	// longer than the process creating them.
	// clang-format off
	if (pthread_mutexattr_setpshared(
				&mutex_attributes, PTHREAD_PROCESS_SHARED) != 0) {
		throw("Error setting process-shared attribute for mutex");
	}

	if (pthread_condattr_setpshared(
				&condition_attributes, PTHREAD_PROCESS_SHARED) != 0) {
		throw("Error setting process-shared attribute for condition variable");
	}
	// clang-format on

	// Initialize the mutex and condition variable and pass the attributes
	if (pthread_mutex_init(&sync->mutex, &mutex_attributes) != 0) {
		throw("Error initializing mutex");
	}
	if (pthread_cond_init(&sync->condition, &condition_attributes) != 0) {
		throw("Error initializing condition variable");
	}

	// Destroy the attribute objects
	if (pthread_mutexattr_destroy(&mutex_attributes)) {
		throw("Error destroying mutex attributes");
	}
	if (pthread_condattr_destroy(&condition_attributes)) {
		throw("Error destroying condition variable attributes");
	}
}
开发者ID:goldsborough,项目名称:ipc-bench,代码行数:55,代码来源:shm-sync-common.c


示例17: qp_cond_create

qp_cond_t
qp_cond_create(qp_cond_t cond, bool shared)
{
    pthread_condattr_t    attr;
    
    if (NULL == cond) {
        cond = (qp_cond_t)qp_alloc(sizeof(struct qp_ipc_cond_s));
        
        if (NULL == cond) {
            return NULL;
        }
        
        memset(cond, 0, sizeof(struct qp_ipc_cond_s));
        qp_cond_set_alloced(cond);
        
    } else {
        memset(cond, 0, sizeof(struct qp_ipc_cond_s));
    }
    
    if (QP_SUCCESS != pthread_condattr_init(&attr)) {
        qp_cond_is_alloced(cond) ? qp_free(cond) : 1;
        return NULL;
    }
    
    if (NULL == qp_lock_init(&cond->cond_lock, shared, false)) {
        qp_cond_is_alloced(cond) ? qp_free(cond) : 1;
        return NULL;
    }
    
#ifdef _POSIX_THREAD_PROCESS_SHARED
    if (shared) {
        
        if (QP_SUCCESS != pthread_condattr_setpshared(&attr,
            PTHREAD_PROCESS_SHARED))
        {
            pthread_condattr_destroy(&attr);
            qp_lock_destroy(&cond->cond_lock);
            qp_cond_is_alloced(cond) ? qp_free(cond) : 1;
            return NULL;
        }
        
        qp_cond_set_shared(cond);
    }
#endif
    
    if (QP_SUCCESS != pthread_cond_init(&(cond->cond), &attr)) {
        pthread_condattr_destroy(&attr);
        qp_lock_destroy(&cond->cond_lock);
        qp_cond_is_alloced(cond) ? qp_free(cond) : 1;
        return NULL;
    }
    
    qp_cond_set_inited(cond);
    return cond;
}
开发者ID:2sui,项目名称:QPHi,代码行数:55,代码来源:qp_ipc_core.c


示例18: main

int main()
{

	/* Make sure there is process-shared capability. */
#ifndef PTHREAD_PROCESS_SHARED
	fprintf(stderr,
		"process-shared attribute is not available for testing\n");
	return PTS_UNRESOLVED;
#endif

	pthread_condattr_t attr[NUM_OF_CONDATTR];
	int ret, i, pshared;

	for (i = 0; i < NUM_OF_CONDATTR; i++) {
		/* Initialize a cond attributes object */
		if (pthread_condattr_init(&attr[i]) != 0) {
			perror("Error at pthread_condattr_init()\n");
			return PTS_UNRESOLVED;
		}

		/* Set 'pshared' to PTHREAD_PROCESS_PRIVATE. */
		ret =
		    pthread_condattr_setpshared(&attr[i],
						PTHREAD_PROCESS_PRIVATE);
		if (ret != 0) {
			printf
			    ("Test FAILED: Could not set pshared to PTHREAD_PROCESS_PRIVATE, error: %d\n",
			     ret);
			return PTS_FAIL;
		}

		/* Get 'pshared'.  It should be PTHREAD_PROCESS_PRIVATE. */
		if (pthread_condattr_getpshared(&attr[i], &pshared) != 0) {
			printf
			    ("Test FAILED: obtaining the wrong process-shared attribute, expected PTHREAD_PROCESS_PRIVATE, but got: %d\n",
			     pshared);
			return PTS_FAIL;
		}

		if (pshared != PTHREAD_PROCESS_PRIVATE) {
			printf("Test FAILED: Incorrect pshared value: %d\n",
			       pshared);
			return PTS_FAIL;
		}

		/* Destory the cond attributes object */
		if (pthread_condattr_destroy(&attr[i]) != 0) {
			perror("Error at pthread_condattr_destroy()\n");
			return PTS_UNRESOLVED;
		}
	}

	printf("Test PASSED\n");
	return PTS_PASS;
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:55,代码来源:1-1.c


示例19: pc_start

void pc_start(int port, int us) {
  assert(!init_check);
  init_check = 1;
  init(&request_list);

  s_port = port;
	use_shared = us;

  args = (struct pt_args_t **) malloc(sizeof(struct pt_args_t*)*MAX_PROXY_THREADS);

  pthreads = (pthread_t**) malloc(sizeof(pthread_t)*MAX_PROXY_THREADS);

  int i;
  for(i = 0; i < MAX_PROXY_THREADS; ++i) {
		args[i] = (struct pt_args_t*) malloc(sizeof(struct pt_args_t));
	
		args[i]->request_list = &request_list;
		args[i]->done = 0;
		args[i]->use_shared = us;
		args[i]->id = i;
		if(use_shared) {
			if( shared_manage( &(args[i]->share), &(args[i]->shmid), i+0xab, sizeof(struct shm_thread_t)) )
				exit(1);
			args[i]->share->proxy = 1;
			if(!args[i]->share->init) {
				{
					pthread_mutexattr_t attr;
					pthread_mutexattr_init(&attr);
					if(pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED)) perror("shm_mutex");
					if(pthread_mutex_init(&(args[i]->share->lock), &attr)) perror("shm_mutex_init");
					pthread_mutexattr_destroy(&attr);
				}

				{
					pthread_condattr_t attr;
					pthread_condattr_init(&attr);
					if(pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED)) perror("shm_cond");
					if(pthread_cond_init(&(args[i]->share->sig), &attr)) perror("shm_cond_init");
					pthread_condattr_destroy(&attr);
				}

				args[i]->share->init = 1;
			}
		}
		else
			args[i]->share = NULL;

		pthreads[i] = (pthread_t *) malloc(sizeof(pthread_t));
		assert(pthreads[i]);
		pthread_create(pthreads[i], NULL, pt_thread, (void*) args[i]);
  }

  pthread_create(&manager, NULL, pc_manager, NULL);
  
}
开发者ID:jcline,项目名称:HTTP-Server,代码行数:55,代码来源:pcontrol.c


示例20: ERROR_CHECK_RET

// Constructor
CondVariableXp::CondVariableXp (clockid_t clk_id, int pshared ){
	pthread_condattr_t attr;

	ERROR_CHECK_RET (pthread_condattr_init (&attr), "CondVariableXp", "pthread_condattr_init");

	ERROR_CHECK_RET (pthread_condattr_setclock  (&attr, clk_id), "CondVariableXp", "pthread_condattr_setclock");
	ERROR_CHECK_RET (pthread_condattr_setpshared (&attr, pshared), "CondVariableXp", "pthread_condattr_setpshared");

	ERROR_CHECK_RET (pthread_cond_init (&condVar, &attr), "CondVariableXp", "pthread_cond_init");

	ERROR_CHECK_RET (pthread_condattr_destroy (&attr), "CondVariableXp", "pthread_condattr_destroy");
}
开发者ID:Said-Nuri,项目名称:xenomai-posix,代码行数:13,代码来源:CondVariableXp.hpp



注:本文中的pthread_condattr_setpshared函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pthread_create函数代码示例发布时间:2022-05-30
下一篇:
C++ pthread_condattr_setclock函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap