小编Eag*_*One的帖子

消息队列中的两种消息类型

我正在编写一个启动两个进程的程序.

第一个进程,"客户端"发送两种类型的消息.

第一种类型增加了共享资源(int).第二种类型将资源设置为0.

在10条消息之后,客户端必须发送一个特殊类型的消息,该消息强制侦听两个队列的线程停止.因此,客户端在类型字段中发送两条带有特殊值的消息(每个队列一个),以终止线程.

第二个过程是"服务器".

服务器有三个线程:

第一个是监听"增加"队列.它必须处理增加请求,直到终止消息.所以我写道:

do{
msgrcv(id_i,&msg,dimensione,INCREMENTA,0);
 pthread_mutex_lock(&mutex);
 printf("THREAD 1: Il contatore vale:%d\n",*contatore);
 incremento = msg.contenuto;
 printf("THREAD 1: Incremento di : %d\n",incremento);
  *contatore+=incremento;
 printf("THREAD 1: Il contatore vale:%d\n",*contatore);
 pthread_mutex_unlock(&mutex);
 msgrcv(id_i,&msg,dimensione,TERMINA,IPC_NOWAIT); //IPC_NOWAIT or the thread will
 freeze after the first message
}
while(msg.tipo!=TERMINA);
Run Code Online (Sandbox Code Playgroud)

第二个必须处理"设置为0"请求,直到终止消息.

do{msgrcv(id_a,&msg,dimensione,AZZERA,0);
pthread_mutex_lock(&mutex);
printf("THREAD 2: IL CONTATORE VALE:%d\n",*contatore);
*contatore=0;
printf("Thread 2: Contatore azzerato. Ora vale : %d\n",*contatore);
pthread_mutex_unlock(&mutex);
 msgrcv(id_a,&msg,dimensione,TERMINA,IPC_NOWAIT);//IPC_NOWAIT or the thread will
 freeze after the first message
 }
while(msg.tipo!=TERMINA);
Run Code Online (Sandbox Code Playgroud)

第三个线程使用互斥锁增加资源的值以进入互斥.

问题是服务器进程的thread1和thread2没有终止它们应该的位置.事实上,他们在所有增加/ set0消息之后停留在第一个msgrcv()上.所以问题是两个线程无法管理监听终止消息.

我试图为第一个msgrcv设置IPC_NOWAIT但是没有用

c multithreading multiprocess

9
推荐指数
1
解决办法
1604
查看次数

无法运行或拉取 Windows docker 镜像

这里我无法拉取或运行任何 Windows docker 映像(从 Windows 或 Linux)

从 Windows cmd 尝试时:

拉:

docker pull mcr.microsoft.com/windows
Using default tag: latest
Error response from daemon: manifest for mcr.microsoft.com/windows:latest not found: manifest unknown: manifest tagged by "latest" is not found
Run Code Online (Sandbox Code Playgroud)

跑步:

docker run mcr.microsoft.com/windows:1903
Unable to find image 'mcr.microsoft.com/windows:1903' locally
1903: Pulling from windows
docker: no matching manifest for linux/amd64 in the manifest list entries.
See 'docker run --help'.
Run Code Online (Sandbox Code Playgroud)

有小费吗?

windows docker

6
推荐指数
1
解决办法
4306
查看次数

超类对象的数组.如何将它们作为子类管理?

有这些课程:

public abstract class Furniture

public class Chair : Furniture

public class Table : Furniture

public class Kitchen
{
ArrayList <Furniture> furnitures;
//other code
public void function ()
{
  Furniture furniture = furnitures.get();
  doSomethingInKitchen(furniture);
}


private void doSomethingInKitchen (Chair c);
private void doSomethingInKitchen (Table t);

}
Run Code Online (Sandbox Code Playgroud)

我正在寻找最佳实践,以确保我将Superclass Furniture对象作为子类(Chair或Table)进行操作.

我尝试了一个简单的演员,但是当我调用它时,它使用Furniture对象操作,而不是使用Table或Chair.

我尝试过的是:

for each Furniture in Array List
if(furniture.get() istance of Table)
{
currentFurniture = (Table) furniture.get();
}

else if (furniture.get() istanceof Chair)
{
currentFurniture = (Chair) furniture.get();
}
doSomethingInKitchen(currentFurniture)
Run Code Online (Sandbox Code Playgroud)

我不知道问题是currentFurniture是否被声明为

Furniture …
Run Code Online (Sandbox Code Playgroud)

java inheritance subclass superclass

5
推荐指数
1
解决办法
1705
查看次数

使用Java/Liberty连接到Bluemix上的DB2数据库

我们有一个存储在Bluemix中的DB2数据库.

由于DB2驱动程序与Android不兼容,因此我们必须在应用程序和Bluemix之间设置一个层.

我们选择使用Java DB Starter样板.

我们如何在Java/Liberty应用程序中实现创建,读取,更新和删除功能,并通过Android应用程序调用它们?

java android websphere-liberty ibm-cloud

0
推荐指数
1
解决办法
226
查看次数