System and device programming lab3

  1. pthread_cond_wait(buf->notfull,&buf->lock);

    notfull is a pointer,so don‘t need to use &.

  2. if use int *p,needs to allocate space,but use int p[10],don‘t need
  3. use gdb to detect segmentation fault, which usually due to malloc
  4. /*pthread_cond_init: initialize a condition variable: must be done before any thread uses the condition variable for the first time*/
      pthread_cond_init(b->notfull,NULL);
  5. check the urgent_Q first,which is for satisfying priority of serving urgent

service first

6.urgent_Q=(Buffer **)malloc(NUM_OFFICES*sizeof(Buffer *)); it‘s not Buffer

but Buffer*

7./*for(i=0;i<NUM_OFFICES;){
  printf("i=%d\n",i);
  //id[i]=rand()%5;
  pjj=i;
  i++;
  pthread_create(&pj[i],NULL,office,&pjj);// &pj[i],not pj[i]
}*///this way will make order confused of value pjj which may have 1 2 3 3

so can use:

for(i=0;i<NUM_OFFICES;i++){
pjj[i]=i;
pthread_create(&pj[i],NULL,office,&pjj[i]);
}

8.For Buffer **answer_Q:

answer_Q=malloc(NUM_OFFICES*sizeof(Buffer *));

for(i=0;i<k;i++)
   answer_Q[i]=B_init(MaxQue);

For Buffer *special_Q:

special_Q=B_init(MaxQue);

9. have declared some local variable in one function like this:

void* thread_function (void* parameter)
{
   struct parameter * thread_data = (struct parameter *)parameter;
   char buffer[20];
   int temp;
}

Here if I have created two threads then in one thread if buffer & temp is updated so will it effect other thread ?

i mean if there are two thread then does there will be two copy of all local variable?

EDIT : then in which case i need to used thread specific data.? i mean pthread_setspecific & all such stuff

These variables are allocated on the stack, and each thread has its own stack: these variables are private to each thread (they are not shared). (See this answer for more details.)

If you assign thread_data to a global pointer, for example, other threads will be able to access thread_data via the global pointer.

Thread specific data (e.g. pthread_setspecific) is used to create variables that are global, but still specific to each thread (not shared): They are thread-specific global variables.

You need to use thread specific variables when you want global variables, but don‘t want to share them between threads.

conclusion:

  1. take care of  the types declared in the structure.
  2. watch carefully in the picture,like every office has its own urgent_Q,

but answer_Q is for each student,so needs to use in different ways:

urgent_Q[office_no],answer_Q[info.id]

时间: 2024-12-23 00:33:53

System and device programming lab3的相关文章

System and device programming——R&W with semaphore

Readers Precedence when both readers and writers wait,favor readers and writers can write only after all readers read.Using semaphore me1 to let writer need to wait one more signal.e.g.when  writer w1 enters and no readers,w1 can write,then have both

System and Device Programming------lab5(paging and swapping)

CR0:has a control flag PG,If 1, enable paging and use the CR3 register, else disable paging CR2:store the address the program attempted to access. CR3:used to store the address of the top-level structure,enable the processor to translate linear addre

System and Device Programming------questions solved about device

(1) br------ 2 root root 0,21 Feb 12 15:40 /dev/dsk15crw-rw-- 2 root root 7,21 Mar 7 09:29 /dev/rdsk15because the two special files propably refer to same partition,sothey refer to to same device,they are just two files of samedevice,which stands for

Microchip 125 kHz RFID System Design Guide

Passive RFID Basics - AN680 INTRODUCTION Radio Frequency Identification (RFID) systems use radio frequency to identify, locate and track people, assets and animals. Passive RFID systems are composed of three components – a reader (interrogator), pass

AVR Programming Methods

AVR Programming Methods  There are many ways to program AVR microcontrollers. Since many people ask about different ones at one time or another, I thought I'd outline them here so that their questions can be answered quickly and efficiently. Please f

Low-overhead enhancement of reliability of journaled file system using solid state storage and de-duplication

A mechanism is provided in a data processing system for reliable asynchronous solid-state device based de-duplication. Responsive to receiving a write request to write data to the file system, the mechanism sends the write request to the file system,

Cryptographic method and system

The present invention relates to the field of security of electronic data and/or communications. In one form, the invention relates to data security and/or privacy in a distributed and/or decentralised network environment. In another form, the invent

File System Design Case Studies

SRC=http://www.cs.rutgers.edu/~pxk/416/notes/13-fs-studies.html Paul Krzyzanowski April 24, 2014 Introduction We've studied various approaches to file system design. Now we'll look at some real file systems to explore the approaches that were taken i

深入理解Android之设备加密Device Encryption

深入理解Android之设备加密Device Encryption Android从4.4开始就支持一项功能,那就是对设备进行加密.加密自然是为了安全性考虑,由于/system目录是只读的,手机里那些存储设备分区中需要保护的就剩下/data/分区和sdcard了.显然,/data/和sdcard大量存储了用户数据(比如app运行时存储的数据),对他们进行加密非常非常有必要. Android 5.0发布后,为了Android设备在企业中的使用,设备加密这个功能默认就必须启用,但是加密这玩意还是对功